Artificial Intelligence Nanodegree

Computer Vision Capstone

Project: Facial Keypoint Detection


Welcome to the final Computer Vision project in the Artificial Intelligence Nanodegree program!

In this project, you’ll combine your knowledge of computer vision techniques and deep learning to build and end-to-end facial keypoint recognition system! Facial keypoints include points around the eyes, nose, and mouth on any face and are used in many applications, from facial tracking to emotion recognition.

There are three main parts to this project:

Part 1 : Investigating OpenCV, pre-processing, and face detection

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!


*Here's what you need to know to complete the project:

  1. In this notebook, some template code has already been provided for you, and you will need to implement additional functionality to successfully complete this project. You will not need to modify the included code beyond what is requested.

    a. Sections that begin with '(IMPLEMENTATION)' in the header indicate that the following block of code will require additional functionality which you must provide. Instructions will be provided for each section, and the specifics of the implementation are marked in the code block with a 'TODO' statement. Please be sure to read the instructions carefully!

  1. In addition to implementing code, there will be questions that you must answer which relate to the project and your implementation.

    a. Each section where you will answer a question is preceded by a 'Question X' header.

    b. Carefully read each question and provide thorough answers in the following text boxes that begin with 'Answer:'.

Note: Code and Markdown cells can be executed using the Shift + Enter keyboard shortcut. Markdown cells can be edited by double-clicking the cell to enter edit mode.

The rubric contains optional suggestions for enhancing the project beyond the minimum requirements. If you decide to pursue the "(Optional)" sections, you should include the code in this IPython notebook.

Your project submission will be evaluated based on your answers to each of the questions and the code implementations you provide.

Steps to Complete the Project

Each part of the notebook is further broken down into separate steps. Feel free to use the links below to navigate the notebook.

In this project you will get to explore a few of the many computer vision algorithms built into the OpenCV library. This expansive computer vision library is now almost 20 years old and still growing!

The project itself is broken down into three large parts, then even further into separate steps. Make sure to read through each step, and complete any sections that begin with '(IMPLEMENTATION)' in the header; these implementation sections may contain multiple TODOs that will be marked in code. For convenience, we provide links to each of these steps below.

Part 1 : Investigating OpenCV, pre-processing, and face detection

  • Step 0: Detect Faces Using a Haar Cascade Classifier
  • Step 1: Add Eye Detection
  • Step 2: De-noise an Image for Better Face Detection
  • Step 3: Blur an Image and Perform Edge Detection
  • Step 4: Automatically Hide the Identity of an Individual

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

  • Step 5: Create a CNN to Recognize Facial Keypoints
  • Step 6: Compile and Train the Model
  • Step 7: Visualize the Loss and Answer Questions

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!

  • Step 8: Build a Robust Facial Keypoints Detector (Complete the CV Pipeline)

Step 0: Detect Faces Using a Haar Cascade Classifier

Have you ever wondered how Facebook automatically tags images with your friends' faces? Or how high-end cameras automatically find and focus on a certain person's face? Applications like these depend heavily on the machine learning task known as face detection - which is the task of automatically finding faces in images containing people.

At its root face detection is a classification problem - that is a problem of distinguishing between distinct classes of things. With face detection these distinct classes are 1) images of human faces and 2) everything else.

We use OpenCV's implementation of Haar feature-based cascade classifiers to detect human faces in images. OpenCV provides many pre-trained face detectors, stored as XML files on github. We have downloaded one of these detectors and stored it in the detector_architectures directory.

Import Resources

In the next python cell, we load in the required libraries for this section of the project.

In [1]:
# Import required libraries for this section

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import math
import cv2                     # OpenCV library for computer vision
from PIL import Image
import time 

Next, we load in and display a test image for performing face detection.

Note: by default OpenCV assumes the ordering of our image's color channels are Blue, then Green, then Red. This is slightly out of order with most image types we'll use in these experiments, whose color channels are ordered Red, then Green, then Blue. In order to switch the Blue and Red channels of our test image around we will use OpenCV's cvtColor function, which you can read more about by checking out some of its documentation located here. This is a general utility function that can do other transformations too like converting a color image to grayscale, and transforming a standard color image to HSV color space.

In [2]:
# Load in color image for face detection
image = cv2.imread('images/test_image_1.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot our image using subplots to specify a size and title
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[2]:
<matplotlib.image.AxesImage at 0x117ec0198>

There are a lot of people - and faces - in this picture. 13 faces to be exact! In the next code cell, we demonstrate how to use a Haar Cascade classifier to detect all the faces in this test image.

This face detector uses information about patterns of intensity in an image to reliably detect faces under varying light conditions. So, to use this face detector, we'll first convert the image from color to grayscale.

Then, we load in the fully trained architecture of the face detector -- found in the file haarcascade_frontalface_default.xml - and use it on our image to find faces!

To learn more about the parameters of the detector see this post.

In [3]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[3]:
<matplotlib.image.AxesImage at 0x11e0f3198>

In the above code, faces is a numpy array of detected faces, where each row corresponds to a detected face. Each detected face is a 1D array with four entries that specifies the bounding box of the detected face. The first two entries in the array (extracted in the above code as x and y) specify the horizontal and vertical positions of the top left corner of the bounding box. The last two entries in the array (extracted here as w and h) specify the width and height of the box.


Step 1: Add Eye Detections

There are other pre-trained detectors available that use a Haar Cascade Classifier - including full human body detectors, license plate detectors, and more. A full list of the pre-trained architectures can be found here.

To test your eye detector, we'll first read in a new test image with just a single face.

In [4]:
# Load in color image for face detection
image = cv2.imread('images/james.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot the RGB image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[4]:
<matplotlib.image.AxesImage at 0x12441cef0>

Notice that even though the image is a black and white image, we have read it in as a color image and so it will still need to be converted to grayscale in order to perform the most accurate face detection.

So, the next steps will be to convert this image to grayscale, then load OpenCV's face detector and run it with parameters that detect this face accurately.

In [5]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.25, minNeighbors=6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detection')
ax1.imshow(image_with_detections)
Number of faces detected: 1
Out[5]:
<matplotlib.image.AxesImage at 0x12444e4e0>

(IMPLEMENTATION) Add an eye detector to the current face detection setup.

A Haar-cascade eye detector can be included in the same way that the face detector was and, in this first task, it will be your job to do just this.

To set up an eye detector, use the stored parameters of the eye cascade detector, called haarcascade_eye.xml, located in the detector_architectures subdirectory. In the next code cell, create your eye detector and store its detections.

A few notes before you get started:

First, make sure to give your loaded eye detector the variable name

eye_cascade

and give the list of eye regions you detect the variable name

eyes

Second, since we've already run the face detector over this image, you should only search for eyes within the rectangular face regions detected in faces. This will minimize false detections.

Lastly, once you've run your eye detector over the facial detection region, you should display the RGB image with both the face detection boxes (in red) and your eye detections (in green) to verify that everything works as expected.

In [6]:
# Make a copy of the original image to plot rectangle detections
def detect(image, face_cascade, eye_cascade):
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    image_with_detections = np.copy(image)

    assert face_cascade is not None, "No face cascade provided"
    
    # Detect the faces in image
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.25, minNeighbors=6)
    
    # Loop over the detections and draw their corresponding face detection boxes
    for (x,y,w,h) in faces:
        cv2.rectangle(image_with_detections, (x,y), (x+w,y+h),(255,0,0), 3)  

    # Do not change the code above this comment!

    ## TODO: Add eye detection, using haarcascade_eye.xml, to the current face detector algorithm
    if eye_cascade is not None:
        for (x,y,w,h) in faces:
            gray_face = gray[y:y+h, x:x+w]
            color_face = image_with_detections[y:y+h, x:x+w, :]

            ## TODO: Loop over the eye detections and draw their corresponding boxes in green on image_with_detections
    #         print ("Doing eye detection")
            eyes = eye_cascade.detectMultiScale(gray_face, scaleFactor=1.15, minNeighbors=3)
    #         print ("Count of eyes: ", len(eyes))
            for (p,q,r,s) in eyes:
                cv2.rectangle(color_face, (p,q), (p+r,q+s),(0,255,0), 3)
                
    return image_with_detections, faces

eye_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_eye.xml')
image_with_detections, _ = detect(image, face_cascade, eye_cascade)

# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face and Eye Detection')
ax1.imshow(image_with_detections)
Out[6]:
<matplotlib.image.AxesImage at 0x1244c5438>

(Optional) Add face and eye detection to your laptop camera

It's time to kick it up a notch, and add face and eye detection to your laptop's camera! Afterwards, you'll be able to show off your creation like in the gif shown below - made with a completed version of the code!

img

Notice that not all of the detections here are perfect - and your result need not be perfect either. You should spend a small amount of time tuning the parameters of your detectors to get reasonable results, but don't hold out for perfection. If we wanted perfection we'd need to spend a ton of time tuning the parameters of each detector, cleaning up the input image frames, etc. You can think of this as more of a rapid prototype.

The next cell contains code for a wrapper function called laptop_camera_face_eye_detector that, when called, will activate your laptop's camera. You will place the relevant face and eye detection code in this wrapper function to implement face/eye detection and mark those detections on each image frame that your camera captures.

Before adding anything to the function, you can run it to get an idea of how it works - a small window should pop up showing you the live feed from your camera; you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [7]:
### Add face and eye detection to this laptop camera function 
# Make sure to draw out all faces/eyes found in each frame on the shown video feed

import cv2
import time 
import random

# wrapper function for face/eye detection with your laptop camera
def laptop_camera_go():
    face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
    eye_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_eye.xml')
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep the video stream open
    while rval:
        # Plot the image from camera with all the face and eye detections marked
        frame, _ = detect(frame, face_cascade, eye_cascade)
                
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            # Make sure window closes on OSx
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
In [8]:
# Call the laptop camera face/eye detector function above
# laptop_camera_go()

Step 2: De-noise an Image for Better Face Detection

Image quality is an important aspect of any computer vision task. Typically, when creating a set of images to train a deep learning network, significant care is taken to ensure that training images are free of visual noise or artifacts that hinder object detection. While computer vision algorithms - like a face detector - are typically trained on 'nice' data such as this, new test data doesn't always look so nice!

When applying a trained computer vision algorithm to a new piece of test data one often cleans it up first before feeding it in. This sort of cleaning - referred to as pre-processing - can include a number of cleaning phases like blurring, de-noising, color transformations, etc., and many of these tasks can be accomplished using OpenCV.

In this short subsection we explore OpenCV's noise-removal functionality to see how we can clean up a noisy image, which we then feed into our trained face detector.

Create a noisy image to work with

In the next cell, we create an artificial noisy version of the previous multi-face image. This is a little exaggerated - we don't typically get images that are this noisy - but image noise, or 'grainy-ness' in a digitial image - is a fairly common phenomenon.

In [9]:
# Load in the multi-face test image again
image = cv2.imread('images/test_image_1.jpg')

# Convert the image copy to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Make an array copy of this image
image_with_noise = np.asarray(image)

# Create noise - here we add noise sampled randomly from a Gaussian distribution: a common model for noise
noise_level = 40
noise = np.random.randn(image.shape[0],image.shape[1],image.shape[2])*noise_level

# Add this noise to the array image copy
image_with_noise = image_with_noise + noise

# Convert back to uint8 format
image_with_noise = np.asarray([np.uint8(np.clip(i,0,255)) for i in image_with_noise])

# Plot our noisy image!
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image')
ax1.imshow(image_with_noise)
Out[9]:
<matplotlib.image.AxesImage at 0x11dd83a20>

In the context of face detection, the problem with an image like this is that - due to noise - we may miss some faces or get false detections.

In the next cell we apply the same trained OpenCV detector with the same settings as before, to see what sort of detections we get.

In [10]:
# Convert the RGB  image to grayscale
gray_noise = cv2.cvtColor(image_with_noise, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_noise, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_with_noise)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 12
Out[10]:
<matplotlib.image.AxesImage at 0x1244582e8>

With this added noise we now miss one of the faces!

(IMPLEMENTATION) De-noise this image for better face detection

Time to get your hands dirty: using OpenCV's built in color image de-noising functionality called fastNlMeansDenoisingColored - de-noise this image enough so that all the faces in the image are properly detected. Once you have cleaned the image in the next cell, use the cell that follows to run our trained face detector over the cleaned image to check out its detections.

You can find its official documentation here and a useful example here.

Note: you can keep all parameters except photo_render fixed as shown in the second link above. Play around with the value of this parameter - see how it affects the resulting cleaned image.

In [11]:
## TODO: Use OpenCV's built in color image de-noising function to clean up our noisy image!


denoised_image = cv2.fastNlMeansDenoisingColored(src=image_with_noise, dst=None, h=13, hColor=10, templateWindowSize=7, searchWindowSize=21)# your final de-noised image (should be RGB)

fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('De-Noised Image')
ax1.imshow(denoised_image)
Out[11]:
<matplotlib.image.AxesImage at 0x12447f630>
In [12]:
## TODO: Run the face detector on the de-noised image to improve your detections and display the result

# Convert the RGB  image to grayscale
gray_denoised = cv2.cvtColor(denoised_image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_denoised, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
denoised_image_with_detections = np.copy(denoised_image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(denoised_image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image with Face Detections')
ax1.imshow(denoised_image_with_detections)
Number of faces detected: 13
Out[12]:
<matplotlib.image.AxesImage at 0x1244e2550>

Step 3: Blur an Image and Perform Edge Detection

Now that we have developed a simple pipeline for detecting faces using OpenCV - let's start playing around with a few fun things we can do with all those detected faces!

Importance of Blur in Edge Detection

Edge detection is a concept that pops up almost everywhere in computer vision applications, as edge-based features (as well as features built on top of edges) are often some of the best features for e.g., object detection and recognition problems.

Edge detection is a dimension reduction technique - by keeping only the edges of an image we get to throw away a lot of non-discriminating information. And typically the most useful kind of edge-detection is one that preserves only the important, global structures (ignoring local structures that aren't very discriminative). So removing local structures / retaining global structures is a crucial pre-processing step to performing edge detection in an image, and blurring can do just that.

Below is an animated gif showing the result of an edge-detected cat taken from Wikipedia, where the image is gradually blurred more and more prior to edge detection. When the animation begins you can't quite make out what it's a picture of, but as the animation evolves and local structures are removed via blurring the cat becomes visible in the edge-detected image.

Edge detection is a convolution performed on the image itself, and you can read about Canny edge detection on this OpenCV documentation page.

Canny edge detection

In the cell below we load in a test image, then apply Canny edge detection on it. The original image is shown on the left panel of the figure, while the edge-detected version of the image is shown on the right. Notice how the result looks very busy - there are too many little details preserved in the image before it is sent to the edge detector. When applied in computer vision applications, edge detection should preserve global structure; doing away with local structures that don't help describe what objects are in the image.

In [13]:
# Load in the image
image = cv2.imread('images/fawzia.jpg')

# Convert to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  

# Perform Canny edge detection
edges = cv2.Canny(gray,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[13]:
<matplotlib.image.AxesImage at 0x12eaed4a8>

Without first blurring the image, and removing small, local structures, a lot of irrelevant edge content gets picked up and amplified by the detector (as shown in the right panel above).

(IMPLEMENTATION) Blur the image then perform edge detection

In the next cell, you will repeat this experiment - blurring the image first to remove these local structures, so that only the important boudnary details remain in the edge-detected image.

Blur the image by using OpenCV's filter2d functionality - which is discussed in this documentation page - and use an averaging kernel of width equal to 4.

In [14]:
### TODO: Blur the test imageusing OpenCV's filter2d functionality, 
# Use an averaging kernel, and a kernel width equal to 4

averaging_kernel = np.ones((4,4),np.float32)/16
blurred_image = cv2.filter2D(gray,-1, averaging_kernel)
    
## TODO: Then perform Canny edge detection and display the output
wide = cv2.dilate(cv2.Canny(blurred_image, 20, 190), None)
tight = cv2.dilate(cv2.Canny(blurred_image, 70, 120), None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Wide Detections')
ax1.imshow(wide, cmap='gray')

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Narrow Detections')
ax2.imshow(tight, cmap='gray')
Out[14]:
<matplotlib.image.AxesImage at 0x12eac20f0>

Step 4: Automatically Hide the Identity of an Individual

If you film something like a documentary or reality TV, you must get permission from every individual shown on film before you can show their face, otherwise you need to blur it out - by blurring the face a lot (so much so that even the global structures are obscured)! This is also true for projects like Google's StreetView maps - an enormous collection of mapping images taken from a fleet of Google vehicles. Because it would be impossible for Google to get the permission of every single person accidentally captured in one of these images they blur out everyone's faces, the detected images must automatically blur the identity of detected people. Here's a few examples of folks caught in the camera of a Google street view vehicle.

Read in an image to perform identity detection

Let's try this out for ourselves. Use the face detection pipeline built above and what you know about using the filter2D to blur and image, and use these in tandem to hide the identity of the person in the following image - loaded in and printed in the next cell.

In [15]:
# Load in the image
image = cv2.imread('images/gus.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[15]:
<matplotlib.image.AxesImage at 0x12ea64908>

(IMPLEMENTATION) Use blurring to hide the identity of an individual in an image

The idea here is to 1) automatically detect the face in this image, and then 2) blur it out! Make sure to adjust the parameters of the averaging blur filter to completely obscure this person's identity.

In [16]:
def censor(image):
    ## TODO: Implement face detection
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    faces_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
    faces = faces_cascade.detectMultiScale(gray, 1.10, 10)
#     print ("Faces detected: ", len(faces))

    ## TODO: Blur the bounding box around each detected face using an averaging filter and display the result
    censored_image = np.copy(image)
#     print(censored_image.shape)
    averaging_kernel = np.ones((61,61),np.float32)/(61*61)
    for (x,y,w,h) in faces:
#         print(x,y,w,h)
        face = censored_image[y:y+h, x:x+w, :]
#         print (face.shape)
    #     face = cv2.GaussianBlur(face,(49, 49), 30) # This does a good blurring. Saving for future reference!
        face = cv2.filter2D(face, -1, averaging_kernel) #
        censored_image[y:y+h, x:x+w, :] = face

    for (x,y,w,h) in faces:
        cv2.rectangle(censored_image, (x,y), (x+w,y+h), (255,0,0), 5)
    
    return censored_image

censored_image = censor(image)

# Display the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Concealed Image')
ax1.imshow(censored_image, cmap='gray')
Out[16]:
<matplotlib.image.AxesImage at 0x1311c8d30>

(Optional) Build identity protection into your laptop camera

In this optional task you can add identity protection to your laptop camera, using the previously completed code where you added face detection to your laptop camera - and the task above. You should be able to get reasonable results with little parameter tuning - like the one shown in the gif below.

img

As with the previous video task, to make this perfect would require significant effort - so don't strive for perfection here, strive for reasonable quality.

The next cell contains code a wrapper function called laptop_camera_identity_hider that - when called - will activate your laptop's camera. You need to place the relevant face detection and blurring code developed above in this function in order to blur faces entering your laptop camera's field of view.

Before adding anything to the function you can call it to get a hang of how it works - a small window will pop up showing you the live feed from your camera, you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [17]:
### Insert face detection and blurring code into the wrapper below to create an identity protector on your laptop!
import cv2
import time 

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        frame = censor(frame)
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [18]:
# Run laptop identity hider
# laptop_camera_go()

Step 5: Create a CNN to Recognize Facial Keypoints

OpenCV is often used in practice with other machine learning and deep learning libraries to produce interesting results. In this stage of the project you will create your own end-to-end pipeline - employing convolutional networks in keras along with OpenCV - to apply a "selfie" filter to streaming video and images.

You will start by creating and then training a convolutional network that can detect facial keypoints in a small dataset of cropped images of human faces. We then guide you towards OpenCV to expanding your detection algorithm to more general images. What are facial keypoints? Let's take a look at some examples.

Facial keypoints (also called facial landmarks) are the small blue-green dots shown on each of the faces in the image above - there are 15 keypoints marked in each image. They mark important areas of the face - the eyes, corners of the mouth, the nose, etc. Facial keypoints can be used in a variety of machine learning applications from face and emotion recognition to commercial applications like the image filters popularized by Snapchat.

Below we illustrate a filter that, using the results of this section, automatically places sunglasses on people in images (using the facial keypoints to place the glasses correctly on each face). Here, the facial keypoints have been colored lime green for visualization purposes.

Make a facial keypoint detector

But first things first: how can we make a facial keypoint detector? Well, at a high level, notice that facial keypoint detection is a regression problem. A single face corresponds to a set of 15 facial keypoints (a set of 15 corresponding $(x, y)$ coordinates, i.e., an output point). Because our input data are images, we can employ a convolutional neural network to recognize patterns in our images and learn how to identify these keypoint given sets of labeled data.

In order to train a regressor, we need a training set - a set of facial image / facial keypoint pairs to train on. For this we will be using this dataset from Kaggle. We've already downloaded this data and placed it in the data directory. Make sure that you have both the training and test data files. The training dataset contains several thousand $96 \times 96$ grayscale images of cropped human faces, along with each face's 15 corresponding facial keypoints (also called landmarks) that have been placed by hand, and recorded in $(x, y)$ coordinates. This wonderful resource also has a substantial testing set, which we will use in tinkering with our convolutional network.

To load in this data, run the Python cell below - notice we will load in both the training and testing sets.

The load_data function is in the included utils.py file.

In [19]:
from utils import *

# Load training set
X_train, y_train = load_data()
print("X_train.shape == {}".format(X_train.shape))
print("y_train.shape == {}; y_train.min == {:.3f}; y_train.max == {:.3f}".format(
    y_train.shape, y_train.min(), y_train.max()))

# Load testing set
X_test, _ = load_data(test=True)
print("X_test.shape == {}".format(X_test.shape))
/Users/safdar/anaconda3/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
X_train.shape == (2140, 96, 96, 1)
y_train.shape == (2140, 30); y_train.min == -0.920; y_train.max == 0.996
X_test.shape == (1783, 96, 96, 1)

The load_data function in utils.py originates from this excellent blog post, which you are strongly encouraged to read. Please take the time now to review this function. Note how the output values - that is, the coordinates of each set of facial landmarks - have been normalized to take on values in the range $[-1, 1]$, while the pixel values of each input point (a facial image) have been normalized to the range $[0,1]$.

Note: the original Kaggle dataset contains some images with several missing keypoints. For simplicity, the load_data function removes those images with missing labels from the dataset. As an optional extension, you are welcome to amend the load_data function to include the incomplete data points.

Visualize the Training Data

Execute the code cell below to visualize a subset of the training data.

In [20]:
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_train[i], y_train[i], ax)

For each training image, there are two landmarks per eyebrow (four total), three per eye (six total), four for the mouth, and one for the tip of the nose.

Review the plot_data function in utils.py to understand how the 30-dimensional training labels in y_train are mapped to facial locations, as this function will prove useful for your pipeline.


Step 6: Design, Compile and Train the Model

Specify your architecture below. Once done, you'll need to compile and train the model to detect facial keypoints.

(TRAINING METHOD) First, we will specify the training function that can be re-used when we explore different model architectures.

Use the fit method to train the model. Break off a validation set by setting validation_split=0.2. Save the returned History object in the history variable.

Experiment with your model to minimize the validation loss (measured as mean squared error). A very good model will achieve about 0.0015 loss (though it's possible to do even better). When you have finished training, save your model as an HDF5 file with file path my_model.h5 (or as appropriate for book-keeping).

In [21]:
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam
from keras import metrics
from keras.callbacks import EarlyStopping
from keras import metrics
import os

def train_model(model, model_file, reload=False, train=True, dry=False, epochs=60, batch_size=32, patience=25):
    if reload and os.path.isfile(model_file):
        print ("Continuing training from previous saved model weights...")
        model.load_weights(model_file)
    else:
        print ("Starting training from scratch...")

    ## TODO: Train the model
    if train:
        print ("Training the model...")
        callbacks = []
        callbacks.append(EarlyStopping(monitor='val_loss', min_delta=0.0001, patience=patience, verbose=1, mode='min'))
        print (X_train.shape, y_train.shape, np.min(X_train), np.max(X_train), np.min(y_train), np.max(y_train))
        print (np.max(np.isnan(X_train)))
        print (np.max(np.isnan(y_train)))

        hist = model.fit( X_train, y_train, validation_split=0.2, batch_size=batch_size, nb_epoch=epochs, callbacks=callbacks, verbose=1 )
    else:
        print ("Training disabled.")

    ## TODO: Save the model as model.h5
    if not dry and train:
        model.save(model_file)
    else:
        print ("Saving disabled.")
        
    if train:
        ## TODO: Visualize the training and validation loss of your neural network
        plt.plot(hist.history['acc'])
        plt.plot(hist.history['val_acc'])
        plt.title('Training and validation accuracies')
        plt.ylabel('accuracy')
        plt.xlabel('epoch')
        plt.legend(['train', 'validation'], loc='upper left')
        plt.show()
        # summarize history for training loss and validation loss
        plt.plot(hist.history['loss'])
        plt.plot(hist.history['val_loss'])
        plt.title('Training and validation losses')
        plt.ylabel('loss')
        plt.xlabel('epoch')
        plt.legend(['train', 'validation'], loc='upper left')
        plt.show()
    else:
        print ("Nothing to show because no training was done")

(IMPLEMENTATIONS) Now, we specify various CNN Architectures

In this section, you will specify a neural network for predicting the locations of facial keypoints. Use the code cell below to specify the architecture of your neural network. We have imported some layers that you may find useful for this task, but if you need to use more Keras layers, feel free to import them in the cell.

Your network should accept a $96 \times 96$ grayscale image as input, and it should output a vector with 30 entries, corresponding to the predicted (horizontal and vertical) locations of 15 facial keypoints. If you are not sure where to start, you can find some useful starting architectures in this blog, but you are not permitted to copy any of the architectures that you find online.

Use the compile method to configure the learning process. Experiment with your choice of optimizer; you may have some ideas about which will work best (SGD vs. RMSprop, etc), but take the time to empirically verify your theories.

(3 Convolutions, 1 FCN, Mean Squared Error) - RMSProp - No Dropout

In [48]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-3cn-1fc-nodrop-mse-rmsprop.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
# model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
# model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
# model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='rmsprop',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=60, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_49 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_49 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_50 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_50 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_51 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_51 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
flatten_13 (Flatten)         (None, 3456)              0         
_________________________________________________________________
dense_25 (Dense)             (None, 30)                103710    
=================================================================
Total params: 107,046
Trainable params: 107,046
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0470 - acc: 0.5905 - mean_absolute_error: 0.1333 - mean_squared_error: 0.0470 - val_loss: 0.0106 - val_acc: 0.6519 - val_mean_absolute_error: 0.0808 - val_mean_squared_error: 0.0106
Epoch 2/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0117 - acc: 0.6945 - mean_absolute_error: 0.0835 - mean_squared_error: 0.0117 - val_loss: 0.0076 - val_acc: 0.7056 - val_mean_absolute_error: 0.0683 - val_mean_squared_error: 0.0076
Epoch 3/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0070 - acc: 0.7144 - mean_absolute_error: 0.0645 - mean_squared_error: 0.0070 - val_loss: 0.0041 - val_acc: 0.7360 - val_mean_absolute_error: 0.0483 - val_mean_squared_error: 0.0041
Epoch 4/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0058 - acc: 0.7185 - mean_absolute_error: 0.0565 - mean_squared_error: 0.0058 - val_loss: 0.0081 - val_acc: 0.7453 - val_mean_absolute_error: 0.0730 - val_mean_squared_error: 0.0081
Epoch 5/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0043 - acc: 0.7383 - mean_absolute_error: 0.0490 - mean_squared_error: 0.0043 - val_loss: 0.0057 - val_acc: 0.7453 - val_mean_absolute_error: 0.0611 - val_mean_squared_error: 0.0057
Epoch 6/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0035 - acc: 0.7418 - mean_absolute_error: 0.0456 - mean_squared_error: 0.0035 - val_loss: 0.0031 - val_acc: 0.7523 - val_mean_absolute_error: 0.0429 - val_mean_squared_error: 0.0031
Epoch 7/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0033 - acc: 0.7447 - mean_absolute_error: 0.0423 - mean_squared_error: 0.0033 - val_loss: 0.0022 - val_acc: 0.7570 - val_mean_absolute_error: 0.0341 - val_mean_squared_error: 0.0022
Epoch 8/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0030 - acc: 0.7424 - mean_absolute_error: 0.0412 - mean_squared_error: 0.0030 - val_loss: 0.0019 - val_acc: 0.7617 - val_mean_absolute_error: 0.0310 - val_mean_squared_error: 0.0019
Epoch 9/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0028 - acc: 0.7646 - mean_absolute_error: 0.0402 - mean_squared_error: 0.0028 - val_loss: 0.0026 - val_acc: 0.7757 - val_mean_absolute_error: 0.0389 - val_mean_squared_error: 0.0026
Epoch 10/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0021 - acc: 0.7658 - mean_absolute_error: 0.0345 - mean_squared_error: 0.0021 - val_loss: 0.0028 - val_acc: 0.7757 - val_mean_absolute_error: 0.0405 - val_mean_squared_error: 0.0028
Epoch 11/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7623 - mean_absolute_error: 0.0360 - mean_squared_error: 0.0022 - val_loss: 0.0036 - val_acc: 0.7570 - val_mean_absolute_error: 0.0486 - val_mean_squared_error: 0.0036
Epoch 12/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7634 - mean_absolute_error: 0.0354 - mean_squared_error: 0.0022 - val_loss: 0.0044 - val_acc: 0.7850 - val_mean_absolute_error: 0.0541 - val_mean_squared_error: 0.0044
Epoch 13/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0019 - acc: 0.7716 - mean_absolute_error: 0.0327 - mean_squared_error: 0.0019 - val_loss: 0.0017 - val_acc: 0.7967 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 14/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0017 - acc: 0.7734 - mean_absolute_error: 0.0309 - mean_squared_error: 0.0017 - val_loss: 0.0018 - val_acc: 0.7897 - val_mean_absolute_error: 0.0302 - val_mean_squared_error: 0.0018
Epoch 15/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0017 - acc: 0.7950 - mean_absolute_error: 0.0312 - mean_squared_error: 0.0017 - val_loss: 0.0021 - val_acc: 0.7991 - val_mean_absolute_error: 0.0341 - val_mean_squared_error: 0.0021
Epoch 16/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0017 - acc: 0.7862 - mean_absolute_error: 0.0318 - mean_squared_error: 0.0017 - val_loss: 0.0037 - val_acc: 0.7850 - val_mean_absolute_error: 0.0501 - val_mean_squared_error: 0.0037
Epoch 17/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0015 - acc: 0.7880 - mean_absolute_error: 0.0296 - mean_squared_error: 0.0015 - val_loss: 0.0022 - val_acc: 0.7944 - val_mean_absolute_error: 0.0356 - val_mean_squared_error: 0.0022
Epoch 18/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0014 - acc: 0.7961 - mean_absolute_error: 0.0280 - mean_squared_error: 0.0014 - val_loss: 0.0020 - val_acc: 0.8014 - val_mean_absolute_error: 0.0328 - val_mean_squared_error: 0.0020
Epoch 19/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0015 - acc: 0.8014 - mean_absolute_error: 0.0290 - mean_squared_error: 0.0015 - val_loss: 0.0016 - val_acc: 0.7921 - val_mean_absolute_error: 0.0282 - val_mean_squared_error: 0.0016
Epoch 20/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.8014 - mean_absolute_error: 0.0262 - mean_squared_error: 0.0012 - val_loss: 0.0017 - val_acc: 0.7921 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 21/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0013 - acc: 0.8067 - mean_absolute_error: 0.0265 - mean_squared_error: 0.0013 - val_loss: 0.0018 - val_acc: 0.7897 - val_mean_absolute_error: 0.0319 - val_mean_squared_error: 0.0018
Epoch 22/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.8207 - mean_absolute_error: 0.0267 - mean_squared_error: 0.0012 - val_loss: 0.0046 - val_acc: 0.7710 - val_mean_absolute_error: 0.0576 - val_mean_squared_error: 0.0046
Epoch 23/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.8248 - mean_absolute_error: 0.0252 - mean_squared_error: 0.0012 - val_loss: 0.0021 - val_acc: 0.7874 - val_mean_absolute_error: 0.0349 - val_mean_squared_error: 0.0021
Epoch 24/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.8265 - mean_absolute_error: 0.0251 - mean_squared_error: 0.0012 - val_loss: 0.0018 - val_acc: 0.7804 - val_mean_absolute_error: 0.0314 - val_mean_squared_error: 0.0018
Epoch 25/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0011 - acc: 0.8382 - mean_absolute_error: 0.0257 - mean_squared_error: 0.0011 - val_loss: 0.0016 - val_acc: 0.7897 - val_mean_absolute_error: 0.0282 - val_mean_squared_error: 0.0016
Epoch 26/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0010 - acc: 0.8335 - mean_absolute_error: 0.0245 - mean_squared_error: 0.0010 - val_loss: 0.0028 - val_acc: 0.7897 - val_mean_absolute_error: 0.0419 - val_mean_squared_error: 0.0028
Epoch 27/60
1712/1712 [==============================] - 8s 5ms/step - loss: 9.0188e-04 - acc: 0.8382 - mean_absolute_error: 0.0229 - mean_squared_error: 9.0188e-04 - val_loss: 0.0017 - val_acc: 0.7804 - val_mean_absolute_error: 0.0297 - val_mean_squared_error: 0.0017
Epoch 28/60
1712/1712 [==============================] - 8s 5ms/step - loss: 9.5643e-04 - acc: 0.8423 - mean_absolute_error: 0.0237 - mean_squared_error: 9.5643e-04 - val_loss: 0.0016 - val_acc: 0.7827 - val_mean_absolute_error: 0.0287 - val_mean_squared_error: 0.0016
Epoch 29/60
1712/1712 [==============================] - 8s 5ms/step - loss: 8.6859e-04 - acc: 0.8487 - mean_absolute_error: 0.0223 - mean_squared_error: 8.6859e-04 - val_loss: 0.0021 - val_acc: 0.7874 - val_mean_absolute_error: 0.0340 - val_mean_squared_error: 0.0021
Epoch 30/60
1712/1712 [==============================] - 8s 5ms/step - loss: 8.5493e-04 - acc: 0.8487 - mean_absolute_error: 0.0227 - mean_squared_error: 8.5493e-04 - val_loss: 0.0016 - val_acc: 0.7757 - val_mean_absolute_error: 0.0288 - val_mean_squared_error: 0.0016
Epoch 31/60
1712/1712 [==============================] - 9s 5ms/step - loss: 8.0085e-04 - acc: 0.8598 - mean_absolute_error: 0.0215 - mean_squared_error: 8.0085e-04 - val_loss: 0.0018 - val_acc: 0.7757 - val_mean_absolute_error: 0.0303 - val_mean_squared_error: 0.0018
Epoch 32/60
1712/1712 [==============================] - 8s 5ms/step - loss: 7.7705e-04 - acc: 0.8592 - mean_absolute_error: 0.0216 - mean_squared_error: 7.7705e-04 - val_loss: 0.0027 - val_acc: 0.7640 - val_mean_absolute_error: 0.0411 - val_mean_squared_error: 0.0027
Epoch 33/60
1712/1712 [==============================] - 9s 5ms/step - loss: 8.0666e-04 - acc: 0.8511 - mean_absolute_error: 0.0221 - mean_squared_error: 8.0666e-04 - val_loss: 0.0019 - val_acc: 0.7640 - val_mean_absolute_error: 0.0320 - val_mean_squared_error: 0.0019
Epoch 34/60
1712/1712 [==============================] - 9s 5ms/step - loss: 6.5764e-04 - acc: 0.8662 - mean_absolute_error: 0.0195 - mean_squared_error: 6.5764e-04 - val_loss: 0.0016 - val_acc: 0.7850 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0016
Epoch 35/60
1712/1712 [==============================] - 10s 6ms/step - loss: 7.9875e-04 - acc: 0.8621 - mean_absolute_error: 0.0214 - mean_squared_error: 7.9875e-04 - val_loss: 0.0019 - val_acc: 0.7827 - val_mean_absolute_error: 0.0327 - val_mean_squared_error: 0.0019
Epoch 36/60
1712/1712 [==============================] - 10s 6ms/step - loss: 7.1378e-04 - acc: 0.8779 - mean_absolute_error: 0.0204 - mean_squared_error: 7.1378e-04 - val_loss: 0.0017 - val_acc: 0.7850 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 37/60
1712/1712 [==============================] - 8s 5ms/step - loss: 5.8240e-04 - acc: 0.8768 - mean_absolute_error: 0.0186 - mean_squared_error: 5.8240e-04 - val_loss: 0.0018 - val_acc: 0.7967 - val_mean_absolute_error: 0.0306 - val_mean_squared_error: 0.0018
Epoch 38/60
1712/1712 [==============================] - 10s 6ms/step - loss: 6.1059e-04 - acc: 0.8803 - mean_absolute_error: 0.0192 - mean_squared_error: 6.1059e-04 - val_loss: 0.0018 - val_acc: 0.7921 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0018
Epoch 00038: early stopping

(3 Convolutions, 1 FCN, Mean Squared Error) - RMSProp - Dropout

In [49]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-3cn-1fc-drop-mse-rmsprop.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(Dropout(0.5))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
# model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
# model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
# model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='rmsprop',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=200, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_52 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_52 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_53 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_53 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_54 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_54 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
dropout_9 (Dropout)          (None, 12, 12, 24)        0         
_________________________________________________________________
flatten_14 (Flatten)         (None, 3456)              0         
_________________________________________________________________
dense_26 (Dense)             (None, 30)                103710    
=================================================================
Total params: 107,046
Trainable params: 107,046
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0296 - acc: 0.4410 - mean_absolute_error: 0.1248 - mean_squared_error: 0.0296 - val_loss: 0.0110 - val_acc: 0.6636 - val_mean_absolute_error: 0.0824 - val_mean_squared_error: 0.0110
Epoch 2/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0105 - acc: 0.6069 - mean_absolute_error: 0.0792 - mean_squared_error: 0.0105 - val_loss: 0.0088 - val_acc: 0.7033 - val_mean_absolute_error: 0.0779 - val_mean_squared_error: 0.0088
Epoch 3/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0075 - acc: 0.6711 - mean_absolute_error: 0.0672 - mean_squared_error: 0.0075 - val_loss: 0.0029 - val_acc: 0.7150 - val_mean_absolute_error: 0.0384 - val_mean_squared_error: 0.0029
Epoch 4/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0051 - acc: 0.6898 - mean_absolute_error: 0.0541 - mean_squared_error: 0.0051 - val_loss: 0.0026 - val_acc: 0.7336 - val_mean_absolute_error: 0.0372 - val_mean_squared_error: 0.0026
Epoch 5/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0057 - acc: 0.6974 - mean_absolute_error: 0.0556 - mean_squared_error: 0.0057 - val_loss: 0.0024 - val_acc: 0.7313 - val_mean_absolute_error: 0.0355 - val_mean_squared_error: 0.0024
Epoch 6/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0043 - acc: 0.7179 - mean_absolute_error: 0.0482 - mean_squared_error: 0.0043 - val_loss: 0.0022 - val_acc: 0.7126 - val_mean_absolute_error: 0.0331 - val_mean_squared_error: 0.0022
Epoch 7/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0037 - acc: 0.7296 - mean_absolute_error: 0.0451 - mean_squared_error: 0.0037 - val_loss: 0.0033 - val_acc: 0.7523 - val_mean_absolute_error: 0.0432 - val_mean_squared_error: 0.0033
Epoch 8/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0036 - acc: 0.7243 - mean_absolute_error: 0.0449 - mean_squared_error: 0.0036 - val_loss: 0.0020 - val_acc: 0.7523 - val_mean_absolute_error: 0.0311 - val_mean_squared_error: 0.0020
Epoch 9/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0038 - acc: 0.7272 - mean_absolute_error: 0.0458 - mean_squared_error: 0.0038 - val_loss: 0.0025 - val_acc: 0.7430 - val_mean_absolute_error: 0.0362 - val_mean_squared_error: 0.0025
Epoch 10/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0033 - acc: 0.7190 - mean_absolute_error: 0.0429 - mean_squared_error: 0.0033 - val_loss: 0.0021 - val_acc: 0.7523 - val_mean_absolute_error: 0.0325 - val_mean_squared_error: 0.0021
Epoch 11/60
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0028 - acc: 0.7272 - mean_absolute_error: 0.0398 - mean_squared_error: 0.0028 - val_loss: 0.0017 - val_acc: 0.7664 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 12/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0030 - acc: 0.7512 - mean_absolute_error: 0.0395 - mean_squared_error: 0.0030 - val_loss: 0.0017 - val_acc: 0.7640 - val_mean_absolute_error: 0.0284 - val_mean_squared_error: 0.0017
Epoch 13/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0023 - acc: 0.7430 - mean_absolute_error: 0.0362 - mean_squared_error: 0.0023 - val_loss: 0.0219 - val_acc: 0.6636 - val_mean_absolute_error: 0.1243 - val_mean_squared_error: 0.0219
Epoch 14/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0026 - acc: 0.7518 - mean_absolute_error: 0.0368 - mean_squared_error: 0.0026 - val_loss: 0.0021 - val_acc: 0.7687 - val_mean_absolute_error: 0.0336 - val_mean_squared_error: 0.0021
Epoch 15/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0026 - acc: 0.7541 - mean_absolute_error: 0.0377 - mean_squared_error: 0.0026 - val_loss: 0.0041 - val_acc: 0.7570 - val_mean_absolute_error: 0.0516 - val_mean_squared_error: 0.0041
Epoch 16/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0024 - acc: 0.7488 - mean_absolute_error: 0.0360 - mean_squared_error: 0.0024 - val_loss: 0.0017 - val_acc: 0.7757 - val_mean_absolute_error: 0.0297 - val_mean_squared_error: 0.0017
Epoch 17/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0025 - acc: 0.7593 - mean_absolute_error: 0.0371 - mean_squared_error: 0.0025 - val_loss: 0.0016 - val_acc: 0.7757 - val_mean_absolute_error: 0.0277 - val_mean_squared_error: 0.0016
Epoch 18/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0021 - acc: 0.7611 - mean_absolute_error: 0.0344 - mean_squared_error: 0.0021 - val_loss: 0.0049 - val_acc: 0.7664 - val_mean_absolute_error: 0.0558 - val_mean_squared_error: 0.0049
Epoch 19/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0021 - acc: 0.7675 - mean_absolute_error: 0.0342 - mean_squared_error: 0.0021 - val_loss: 0.0036 - val_acc: 0.7640 - val_mean_absolute_error: 0.0460 - val_mean_squared_error: 0.0036
Epoch 20/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0021 - acc: 0.7582 - mean_absolute_error: 0.0337 - mean_squared_error: 0.0021 - val_loss: 0.0017 - val_acc: 0.7734 - val_mean_absolute_error: 0.0296 - val_mean_squared_error: 0.0017
Epoch 21/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0022 - acc: 0.7786 - mean_absolute_error: 0.0347 - mean_squared_error: 0.0022 - val_loss: 0.0015 - val_acc: 0.7734 - val_mean_absolute_error: 0.0269 - val_mean_squared_error: 0.0015
Epoch 22/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7804 - mean_absolute_error: 0.0334 - mean_squared_error: 0.0020 - val_loss: 0.0034 - val_acc: 0.7664 - val_mean_absolute_error: 0.0464 - val_mean_squared_error: 0.0034
Epoch 23/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0018 - acc: 0.7728 - mean_absolute_error: 0.0317 - mean_squared_error: 0.0018 - val_loss: 0.0018 - val_acc: 0.7710 - val_mean_absolute_error: 0.0317 - val_mean_squared_error: 0.0018
Epoch 24/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7798 - mean_absolute_error: 0.0330 - mean_squared_error: 0.0020 - val_loss: 0.0037 - val_acc: 0.7780 - val_mean_absolute_error: 0.0497 - val_mean_squared_error: 0.0037
Epoch 25/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7780 - mean_absolute_error: 0.0319 - mean_squared_error: 0.0019 - val_loss: 0.0021 - val_acc: 0.7827 - val_mean_absolute_error: 0.0334 - val_mean_squared_error: 0.0021
Epoch 26/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0018 - acc: 0.7658 - mean_absolute_error: 0.0318 - mean_squared_error: 0.0018 - val_loss: 0.0015 - val_acc: 0.7874 - val_mean_absolute_error: 0.0275 - val_mean_squared_error: 0.0015
Epoch 27/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0018 - acc: 0.7769 - mean_absolute_error: 0.0311 - mean_squared_error: 0.0018 - val_loss: 0.0015 - val_acc: 0.7710 - val_mean_absolute_error: 0.0265 - val_mean_squared_error: 0.0015
Epoch 28/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0016 - acc: 0.7792 - mean_absolute_error: 0.0306 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7897 - val_mean_absolute_error: 0.0272 - val_mean_squared_error: 0.0015
Epoch 29/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0017 - acc: 0.7664 - mean_absolute_error: 0.0311 - mean_squared_error: 0.0017 - val_loss: 0.0018 - val_acc: 0.7804 - val_mean_absolute_error: 0.0310 - val_mean_squared_error: 0.0018
Epoch 30/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0018 - acc: 0.7786 - mean_absolute_error: 0.0314 - mean_squared_error: 0.0018 - val_loss: 0.0014 - val_acc: 0.7827 - val_mean_absolute_error: 0.0265 - val_mean_squared_error: 0.0014
Epoch 31/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0016 - acc: 0.7798 - mean_absolute_error: 0.0295 - mean_squared_error: 0.0016 - val_loss: 0.0022 - val_acc: 0.7757 - val_mean_absolute_error: 0.0357 - val_mean_squared_error: 0.0022
Epoch 32/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0016 - acc: 0.7979 - mean_absolute_error: 0.0300 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7944 - val_mean_absolute_error: 0.0267 - val_mean_squared_error: 0.0015
Epoch 33/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0015 - acc: 0.7886 - mean_absolute_error: 0.0294 - mean_squared_error: 0.0015 - val_loss: 0.0015 - val_acc: 0.8037 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 34/60
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0016 - acc: 0.7845 - mean_absolute_error: 0.0299 - mean_squared_error: 0.0016 - val_loss: 0.0020 - val_acc: 0.7991 - val_mean_absolute_error: 0.0328 - val_mean_squared_error: 0.0020
Epoch 35/60
1712/1712 [==============================] - 11s 7ms/step - loss: 0.0015 - acc: 0.7739 - mean_absolute_error: 0.0290 - mean_squared_error: 0.0015 - val_loss: 0.0025 - val_acc: 0.7734 - val_mean_absolute_error: 0.0386 - val_mean_squared_error: 0.0025
Epoch 36/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0015 - acc: 0.7751 - mean_absolute_error: 0.0289 - mean_squared_error: 0.0015 - val_loss: 0.0038 - val_acc: 0.7827 - val_mean_absolute_error: 0.0495 - val_mean_squared_error: 0.0038
Epoch 37/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0016 - acc: 0.7821 - mean_absolute_error: 0.0298 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7827 - val_mean_absolute_error: 0.0271 - val_mean_squared_error: 0.0015
Epoch 38/60
1712/1712 [==============================] - 11s 7ms/step - loss: 0.0014 - acc: 0.7763 - mean_absolute_error: 0.0278 - mean_squared_error: 0.0014 - val_loss: 0.0024 - val_acc: 0.7757 - val_mean_absolute_error: 0.0382 - val_mean_squared_error: 0.0024
Epoch 39/60
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0015 - acc: 0.7868 - mean_absolute_error: 0.0290 - mean_squared_error: 0.0015 - val_loss: 0.0016 - val_acc: 0.7734 - val_mean_absolute_error: 0.0288 - val_mean_squared_error: 0.0016
Epoch 40/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0014 - acc: 0.7880 - mean_absolute_error: 0.0285 - mean_squared_error: 0.0014 - val_loss: 0.0016 - val_acc: 0.7780 - val_mean_absolute_error: 0.0287 - val_mean_squared_error: 0.0016
Epoch 41/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0016 - acc: 0.7868 - mean_absolute_error: 0.0296 - mean_squared_error: 0.0016 - val_loss: 0.0014 - val_acc: 0.7734 - val_mean_absolute_error: 0.0268 - val_mean_squared_error: 0.0014
Epoch 42/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0013 - acc: 0.8107 - mean_absolute_error: 0.0268 - mean_squared_error: 0.0013 - val_loss: 0.0022 - val_acc: 0.7757 - val_mean_absolute_error: 0.0344 - val_mean_squared_error: 0.0022
Epoch 43/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0014 - acc: 0.7967 - mean_absolute_error: 0.0285 - mean_squared_error: 0.0014 - val_loss: 0.0018 - val_acc: 0.7734 - val_mean_absolute_error: 0.0308 - val_mean_squared_error: 0.0018
Epoch 44/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0014 - acc: 0.7839 - mean_absolute_error: 0.0280 - mean_squared_error: 0.0014 - val_loss: 0.0014 - val_acc: 0.7640 - val_mean_absolute_error: 0.0266 - val_mean_squared_error: 0.0014
Epoch 45/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0014 - acc: 0.7886 - mean_absolute_error: 0.0280 - mean_squared_error: 0.0014 - val_loss: 0.0016 - val_acc: 0.7640 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0016
Epoch 46/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0014 - acc: 0.7856 - mean_absolute_error: 0.0279 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7780 - val_mean_absolute_error: 0.0271 - val_mean_squared_error: 0.0015
Epoch 47/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0013 - acc: 0.8055 - mean_absolute_error: 0.0268 - mean_squared_error: 0.0013 - val_loss: 0.0017 - val_acc: 0.7780 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0017
Epoch 48/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0013 - acc: 0.7985 - mean_absolute_error: 0.0273 - mean_squared_error: 0.0013 - val_loss: 0.0015 - val_acc: 0.7944 - val_mean_absolute_error: 0.0267 - val_mean_squared_error: 0.0015
Epoch 49/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0014 - acc: 0.8008 - mean_absolute_error: 0.0277 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7944 - val_mean_absolute_error: 0.0266 - val_mean_squared_error: 0.0015
Epoch 50/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0012 - acc: 0.8131 - mean_absolute_error: 0.0264 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7734 - val_mean_absolute_error: 0.0269 - val_mean_squared_error: 0.0014
Epoch 51/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0013 - acc: 0.7856 - mean_absolute_error: 0.0272 - mean_squared_error: 0.0013 - val_loss: 0.0016 - val_acc: 0.7804 - val_mean_absolute_error: 0.0290 - val_mean_squared_error: 0.0016
Epoch 52/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0013 - acc: 0.8131 - mean_absolute_error: 0.0268 - mean_squared_error: 0.0013 - val_loss: 0.0015 - val_acc: 0.7897 - val_mean_absolute_error: 0.0276 - val_mean_squared_error: 0.0015
Epoch 00052: early stopping

(3 Convolutions, 1 FCN, Mean Squared Error) - Adam - Dropout

In [50]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-3cn-1fc-drop-mse-adam.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(Dropout(0.5))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
# model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
# model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
# model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='adam',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=200, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_55 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_55 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_56 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_56 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_57 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_57 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
dropout_10 (Dropout)         (None, 12, 12, 24)        0         
_________________________________________________________________
flatten_15 (Flatten)         (None, 3456)              0         
_________________________________________________________________
dense_27 (Dense)             (None, 30)                103710    
=================================================================
Total params: 107,046
Trainable params: 107,046
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0270 - acc: 0.4854 - mean_absolute_error: 0.1164 - mean_squared_error: 0.0270 - val_loss: 0.0050 - val_acc: 0.6916 - val_mean_absolute_error: 0.0527 - val_mean_squared_error: 0.0050
Epoch 2/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0067 - acc: 0.6192 - mean_absolute_error: 0.0626 - mean_squared_error: 0.0067 - val_loss: 0.0039 - val_acc: 0.6986 - val_mean_absolute_error: 0.0462 - val_mean_squared_error: 0.0039
Epoch 3/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0052 - acc: 0.6431 - mean_absolute_error: 0.0552 - mean_squared_error: 0.0052 - val_loss: 0.0033 - val_acc: 0.6963 - val_mean_absolute_error: 0.0417 - val_mean_squared_error: 0.0033
Epoch 4/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0045 - acc: 0.6595 - mean_absolute_error: 0.0509 - mean_squared_error: 0.0045 - val_loss: 0.0031 - val_acc: 0.7033 - val_mean_absolute_error: 0.0399 - val_mean_squared_error: 0.0031
Epoch 5/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0039 - acc: 0.6746 - mean_absolute_error: 0.0475 - mean_squared_error: 0.0039 - val_loss: 0.0032 - val_acc: 0.7220 - val_mean_absolute_error: 0.0409 - val_mean_squared_error: 0.0032
Epoch 6/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0036 - acc: 0.6863 - mean_absolute_error: 0.0453 - mean_squared_error: 0.0036 - val_loss: 0.0025 - val_acc: 0.7150 - val_mean_absolute_error: 0.0360 - val_mean_squared_error: 0.0025
Epoch 7/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0033 - acc: 0.6875 - mean_absolute_error: 0.0432 - mean_squared_error: 0.0033 - val_loss: 0.0023 - val_acc: 0.7266 - val_mean_absolute_error: 0.0342 - val_mean_squared_error: 0.0023
Epoch 8/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0031 - acc: 0.6910 - mean_absolute_error: 0.0420 - mean_squared_error: 0.0031 - val_loss: 0.0026 - val_acc: 0.7196 - val_mean_absolute_error: 0.0360 - val_mean_squared_error: 0.0026
Epoch 9/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0029 - acc: 0.6998 - mean_absolute_error: 0.0404 - mean_squared_error: 0.0029 - val_loss: 0.0021 - val_acc: 0.7290 - val_mean_absolute_error: 0.0328 - val_mean_squared_error: 0.0021
Epoch 10/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0028 - acc: 0.7039 - mean_absolute_error: 0.0393 - mean_squared_error: 0.0028 - val_loss: 0.0021 - val_acc: 0.7196 - val_mean_absolute_error: 0.0319 - val_mean_squared_error: 0.0021
Epoch 11/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0027 - acc: 0.7185 - mean_absolute_error: 0.0388 - mean_squared_error: 0.0027 - val_loss: 0.0020 - val_acc: 0.7336 - val_mean_absolute_error: 0.0313 - val_mean_squared_error: 0.0020
Epoch 12/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0027 - acc: 0.7079 - mean_absolute_error: 0.0385 - mean_squared_error: 0.0027 - val_loss: 0.0022 - val_acc: 0.7336 - val_mean_absolute_error: 0.0333 - val_mean_squared_error: 0.0022
Epoch 13/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0025 - acc: 0.7301 - mean_absolute_error: 0.0370 - mean_squared_error: 0.0025 - val_loss: 0.0019 - val_acc: 0.7383 - val_mean_absolute_error: 0.0306 - val_mean_squared_error: 0.0019
Epoch 14/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0024 - acc: 0.7196 - mean_absolute_error: 0.0365 - mean_squared_error: 0.0024 - val_loss: 0.0019 - val_acc: 0.7430 - val_mean_absolute_error: 0.0307 - val_mean_squared_error: 0.0019
Epoch 15/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0024 - acc: 0.7214 - mean_absolute_error: 0.0366 - mean_squared_error: 0.0024 - val_loss: 0.0019 - val_acc: 0.7407 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0019
Epoch 16/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0023 - acc: 0.7155 - mean_absolute_error: 0.0354 - mean_squared_error: 0.0023 - val_loss: 0.0018 - val_acc: 0.7523 - val_mean_absolute_error: 0.0299 - val_mean_squared_error: 0.0018
Epoch 17/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0023 - acc: 0.7255 - mean_absolute_error: 0.0349 - mean_squared_error: 0.0023 - val_loss: 0.0018 - val_acc: 0.7523 - val_mean_absolute_error: 0.0296 - val_mean_squared_error: 0.0018
Epoch 18/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7301 - mean_absolute_error: 0.0342 - mean_squared_error: 0.0022 - val_loss: 0.0018 - val_acc: 0.7523 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0018
Epoch 19/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7407 - mean_absolute_error: 0.0346 - mean_squared_error: 0.0022 - val_loss: 0.0021 - val_acc: 0.7570 - val_mean_absolute_error: 0.0330 - val_mean_squared_error: 0.0021
Epoch 20/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0021 - acc: 0.7307 - mean_absolute_error: 0.0342 - mean_squared_error: 0.0021 - val_loss: 0.0017 - val_acc: 0.7640 - val_mean_absolute_error: 0.0291 - val_mean_squared_error: 0.0017
Epoch 21/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0020 - acc: 0.7354 - mean_absolute_error: 0.0331 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7640 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 22/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0020 - acc: 0.7336 - mean_absolute_error: 0.0328 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7710 - val_mean_absolute_error: 0.0291 - val_mean_squared_error: 0.0017
Epoch 23/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0020 - acc: 0.7547 - mean_absolute_error: 0.0325 - mean_squared_error: 0.0020 - val_loss: 0.0018 - val_acc: 0.7664 - val_mean_absolute_error: 0.0299 - val_mean_squared_error: 0.0018
Epoch 24/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0019 - acc: 0.7418 - mean_absolute_error: 0.0321 - mean_squared_error: 0.0019 - val_loss: 0.0017 - val_acc: 0.7664 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0017
Epoch 25/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0019 - acc: 0.7465 - mean_absolute_error: 0.0320 - mean_squared_error: 0.0019 - val_loss: 0.0017 - val_acc: 0.7664 - val_mean_absolute_error: 0.0284 - val_mean_squared_error: 0.0017
Epoch 26/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0018 - acc: 0.7488 - mean_absolute_error: 0.0314 - mean_squared_error: 0.0018 - val_loss: 0.0016 - val_acc: 0.7687 - val_mean_absolute_error: 0.0279 - val_mean_squared_error: 0.0016
Epoch 27/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7553 - mean_absolute_error: 0.0314 - mean_squared_error: 0.0018 - val_loss: 0.0016 - val_acc: 0.7687 - val_mean_absolute_error: 0.0277 - val_mean_squared_error: 0.0016
Epoch 28/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7424 - mean_absolute_error: 0.0309 - mean_squared_error: 0.0018 - val_loss: 0.0016 - val_acc: 0.7757 - val_mean_absolute_error: 0.0283 - val_mean_squared_error: 0.0016
Epoch 29/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7564 - mean_absolute_error: 0.0305 - mean_squared_error: 0.0017 - val_loss: 0.0016 - val_acc: 0.7710 - val_mean_absolute_error: 0.0274 - val_mean_squared_error: 0.0016
Epoch 30/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7494 - mean_absolute_error: 0.0303 - mean_squared_error: 0.0017 - val_loss: 0.0018 - val_acc: 0.7710 - val_mean_absolute_error: 0.0302 - val_mean_squared_error: 0.0018
Epoch 31/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7459 - mean_absolute_error: 0.0303 - mean_squared_error: 0.0017 - val_loss: 0.0015 - val_acc: 0.7780 - val_mean_absolute_error: 0.0270 - val_mean_squared_error: 0.0015
Epoch 32/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7389 - mean_absolute_error: 0.0299 - mean_squared_error: 0.0017 - val_loss: 0.0015 - val_acc: 0.7804 - val_mean_absolute_error: 0.0270 - val_mean_squared_error: 0.0015
Epoch 33/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0016 - acc: 0.7599 - mean_absolute_error: 0.0295 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7780 - val_mean_absolute_error: 0.0269 - val_mean_squared_error: 0.0015
Epoch 34/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0016 - acc: 0.7646 - mean_absolute_error: 0.0297 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0271 - val_mean_squared_error: 0.0015
Epoch 35/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7553 - mean_absolute_error: 0.0299 - mean_squared_error: 0.0017 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0272 - val_mean_squared_error: 0.0015
Epoch 36/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0016 - acc: 0.7658 - mean_absolute_error: 0.0292 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7640 - val_mean_absolute_error: 0.0266 - val_mean_squared_error: 0.0015
Epoch 37/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0016 - acc: 0.7471 - mean_absolute_error: 0.0296 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7827 - val_mean_absolute_error: 0.0265 - val_mean_squared_error: 0.0015
Epoch 38/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0015 - acc: 0.7652 - mean_absolute_error: 0.0284 - mean_squared_error: 0.0015 - val_loss: 0.0016 - val_acc: 0.7850 - val_mean_absolute_error: 0.0274 - val_mean_squared_error: 0.0016
Epoch 39/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0016 - acc: 0.7617 - mean_absolute_error: 0.0293 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0263 - val_mean_squared_error: 0.0015
Epoch 40/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0015 - acc: 0.7576 - mean_absolute_error: 0.0283 - mean_squared_error: 0.0015 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0263 - val_mean_squared_error: 0.0014
Epoch 41/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0014 - acc: 0.7652 - mean_absolute_error: 0.0279 - mean_squared_error: 0.0014 - val_loss: 0.0014 - val_acc: 0.7921 - val_mean_absolute_error: 0.0261 - val_mean_squared_error: 0.0014
Epoch 42/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0015 - acc: 0.7775 - mean_absolute_error: 0.0280 - mean_squared_error: 0.0015 - val_loss: 0.0016 - val_acc: 0.7874 - val_mean_absolute_error: 0.0282 - val_mean_squared_error: 0.0016
Epoch 43/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0014 - acc: 0.7634 - mean_absolute_error: 0.0277 - mean_squared_error: 0.0014 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0014
Epoch 44/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0014 - acc: 0.7699 - mean_absolute_error: 0.0278 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0267 - val_mean_squared_error: 0.0015
Epoch 45/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0015 - acc: 0.7675 - mean_absolute_error: 0.0280 - mean_squared_error: 0.0015 - val_loss: 0.0015 - val_acc: 0.7944 - val_mean_absolute_error: 0.0271 - val_mean_squared_error: 0.0015
Epoch 46/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0014 - acc: 0.7798 - mean_absolute_error: 0.0279 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7804 - val_mean_absolute_error: 0.0263 - val_mean_squared_error: 0.0015
Epoch 47/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0014 - acc: 0.7850 - mean_absolute_error: 0.0271 - mean_squared_error: 0.0014 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0261 - val_mean_squared_error: 0.0014
Epoch 48/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0013 - acc: 0.7669 - mean_absolute_error: 0.0269 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0257 - val_mean_squared_error: 0.0014
Epoch 49/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7769 - mean_absolute_error: 0.0270 - mean_squared_error: 0.0013 - val_loss: 0.0015 - val_acc: 0.7944 - val_mean_absolute_error: 0.0275 - val_mean_squared_error: 0.0015
Epoch 50/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0013 - acc: 0.7780 - mean_absolute_error: 0.0268 - mean_squared_error: 0.0013 - val_loss: 0.0015 - val_acc: 0.7967 - val_mean_absolute_error: 0.0269 - val_mean_squared_error: 0.0015
Epoch 51/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7669 - mean_absolute_error: 0.0269 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7897 - val_mean_absolute_error: 0.0257 - val_mean_squared_error: 0.0014
Epoch 52/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7769 - mean_absolute_error: 0.0264 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7944 - val_mean_absolute_error: 0.0257 - val_mean_squared_error: 0.0014
Epoch 53/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7763 - mean_absolute_error: 0.0265 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7827 - val_mean_absolute_error: 0.0263 - val_mean_squared_error: 0.0014
Epoch 54/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7739 - mean_absolute_error: 0.0265 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7874 - val_mean_absolute_error: 0.0256 - val_mean_squared_error: 0.0014
Epoch 55/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7804 - mean_absolute_error: 0.0261 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7874 - val_mean_absolute_error: 0.0255 - val_mean_squared_error: 0.0014
Epoch 56/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0013 - acc: 0.7710 - mean_absolute_error: 0.0263 - mean_squared_error: 0.0013 - val_loss: 0.0015 - val_acc: 0.7897 - val_mean_absolute_error: 0.0267 - val_mean_squared_error: 0.0015
Epoch 57/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7839 - mean_absolute_error: 0.0258 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0258 - val_mean_squared_error: 0.0014
Epoch 58/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7810 - mean_absolute_error: 0.0259 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7967 - val_mean_absolute_error: 0.0255 - val_mean_squared_error: 0.0014
Epoch 59/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7850 - mean_absolute_error: 0.0257 - mean_squared_error: 0.0012 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0268 - val_mean_squared_error: 0.0015
Epoch 60/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7856 - mean_absolute_error: 0.0259 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0264 - val_mean_squared_error: 0.0014
Epoch 61/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7804 - mean_absolute_error: 0.0257 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_acc: 0.7850 - val_mean_absolute_error: 0.0252 - val_mean_squared_error: 0.0013
Epoch 62/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7839 - mean_absolute_error: 0.0253 - mean_squared_error: 0.0012 - val_loss: 0.0015 - val_acc: 0.7874 - val_mean_absolute_error: 0.0270 - val_mean_squared_error: 0.0015
Epoch 63/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7780 - mean_absolute_error: 0.0266 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0014
Epoch 64/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7862 - mean_absolute_error: 0.0249 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7944 - val_mean_absolute_error: 0.0257 - val_mean_squared_error: 0.0014
Epoch 65/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.7891 - mean_absolute_error: 0.0255 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0256 - val_mean_squared_error: 0.0014
Epoch 66/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7856 - mean_absolute_error: 0.0248 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7921 - val_mean_absolute_error: 0.0256 - val_mean_squared_error: 0.0014
Epoch 67/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7967 - mean_absolute_error: 0.0248 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7921 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 68/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7868 - mean_absolute_error: 0.0250 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7897 - val_mean_absolute_error: 0.0251 - val_mean_squared_error: 0.0013
Epoch 69/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7950 - mean_absolute_error: 0.0247 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7967 - val_mean_absolute_error: 0.0252 - val_mean_squared_error: 0.0013
Epoch 70/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7886 - mean_absolute_error: 0.0246 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7967 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 71/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7991 - mean_absolute_error: 0.0244 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7944 - val_mean_absolute_error: 0.0249 - val_mean_squared_error: 0.0013
Epoch 72/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7909 - mean_absolute_error: 0.0242 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7921 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 73/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0011 - acc: 0.7921 - mean_absolute_error: 0.0244 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7967 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 74/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7769 - mean_absolute_error: 0.0247 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7897 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 75/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7932 - mean_absolute_error: 0.0242 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7897 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 76/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7845 - mean_absolute_error: 0.0247 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.8037 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 77/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7950 - mean_absolute_error: 0.0240 - mean_squared_error: 0.0011 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0272 - val_mean_squared_error: 0.0015
Epoch 78/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.8049 - mean_absolute_error: 0.0244 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7991 - val_mean_absolute_error: 0.0252 - val_mean_squared_error: 0.0013
Epoch 79/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.8037 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7991 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 80/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.8032 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7944 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0013
Epoch 81/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7897 - mean_absolute_error: 0.0243 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.8037 - val_mean_absolute_error: 0.0262 - val_mean_squared_error: 0.0014
Epoch 82/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.7880 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7897 - val_mean_absolute_error: 0.0253 - val_mean_squared_error: 0.0013
Epoch 83/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.7961 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7827 - val_mean_absolute_error: 0.0255 - val_mean_squared_error: 0.0013
Epoch 84/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.7996 - mean_absolute_error: 0.0241 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7874 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0013
Epoch 85/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.7967 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7967 - val_mean_absolute_error: 0.0255 - val_mean_squared_error: 0.0013
Epoch 86/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.7921 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7804 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 87/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0010 - acc: 0.7996 - mean_absolute_error: 0.0235 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.8107 - val_mean_absolute_error: 0.0245 - val_mean_squared_error: 0.0013
Epoch 88/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0010 - acc: 0.7944 - mean_absolute_error: 0.0234 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7991 - val_mean_absolute_error: 0.0244 - val_mean_squared_error: 0.0013
Epoch 89/200
1712/1712 [==============================] - 11s 6ms/step - loss: 9.9620e-04 - acc: 0.7956 - mean_absolute_error: 0.0233 - mean_squared_error: 9.9620e-04 - val_loss: 0.0013 - val_acc: 0.7944 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 90/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.8090 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.8014 - val_mean_absolute_error: 0.0253 - val_mean_squared_error: 0.0013
Epoch 91/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.8589e-04 - acc: 0.8020 - mean_absolute_error: 0.0234 - mean_squared_error: 9.8589e-04 - val_loss: 0.0013 - val_acc: 0.7967 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 92/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.6646e-04 - acc: 0.8078 - mean_absolute_error: 0.0231 - mean_squared_error: 9.6646e-04 - val_loss: 0.0013 - val_acc: 0.8107 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 93/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.3946e-04 - acc: 0.8008 - mean_absolute_error: 0.0229 - mean_squared_error: 9.3946e-04 - val_loss: 0.0013 - val_acc: 0.8061 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 94/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.6751e-04 - acc: 0.7996 - mean_absolute_error: 0.0231 - mean_squared_error: 9.6751e-04 - val_loss: 0.0013 - val_acc: 0.7757 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 95/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.9101e-04 - acc: 0.8119 - mean_absolute_error: 0.0235 - mean_squared_error: 9.9101e-04 - val_loss: 0.0013 - val_acc: 0.8107 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0013
Epoch 96/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.5649e-04 - acc: 0.7886 - mean_absolute_error: 0.0230 - mean_squared_error: 9.5649e-04 - val_loss: 0.0014 - val_acc: 0.8037 - val_mean_absolute_error: 0.0260 - val_mean_squared_error: 0.0014
Epoch 00096: early stopping

(3 Convolutions, 1 FCN, Mean Squared Error) - Adam - Dropout - Batchnorm

In [58]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense, BatchNormalization

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-3cn-1fc-drop-batchnorm-mse-adam.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
model.add(Dropout(0.5))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
# model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
# model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
# model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='adam',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=200, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_86 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_86 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
batch_normalization_25 (Batc (None, 48, 48, 6)         24        
_________________________________________________________________
conv2d_87 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_87 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
batch_normalization_26 (Batc (None, 24, 24, 12)        48        
_________________________________________________________________
conv2d_88 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_88 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
batch_normalization_27 (Batc (None, 12, 12, 24)        96        
_________________________________________________________________
dropout_14 (Dropout)         (None, 12, 12, 24)        0         
_________________________________________________________________
flatten_22 (Flatten)         (None, 3456)              0         
_________________________________________________________________
dense_39 (Dense)             (None, 30)                103710    
=================================================================
Total params: 107,214
Trainable params: 107,130
Non-trainable params: 84
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/200
1712/1712 [==============================] - 10s 6ms/step - loss: 2.3420 - acc: 0.0794 - mean_absolute_error: 1.1780 - mean_squared_error: 2.3420 - val_loss: 0.5710 - val_acc: 0.2593 - val_mean_absolute_error: 0.5817 - val_mean_squared_error: 0.5710
Epoch 2/200
1712/1712 [==============================] - 7s 4ms/step - loss: 1.5666 - acc: 0.0999 - mean_absolute_error: 0.9579 - mean_squared_error: 1.5666 - val_loss: 0.2955 - val_acc: 0.2500 - val_mean_absolute_error: 0.4145 - val_mean_squared_error: 0.2955
Epoch 3/200
1712/1712 [==============================] - 7s 4ms/step - loss: 1.1653 - acc: 0.1098 - mean_absolute_error: 0.8238 - mean_squared_error: 1.1653 - val_loss: 0.2283 - val_acc: 0.1963 - val_mean_absolute_error: 0.3523 - val_mean_squared_error: 0.2283
Epoch 4/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.8709 - acc: 0.1186 - mean_absolute_error: 0.7134 - mean_squared_error: 0.8709 - val_loss: 0.1475 - val_acc: 0.2196 - val_mean_absolute_error: 0.2948 - val_mean_squared_error: 0.1475
Epoch 5/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.6651 - acc: 0.1460 - mean_absolute_error: 0.6243 - mean_squared_error: 0.6651 - val_loss: 0.1041 - val_acc: 0.3154 - val_mean_absolute_error: 0.2494 - val_mean_squared_error: 0.1041
Epoch 6/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.5253 - acc: 0.1443 - mean_absolute_error: 0.5537 - mean_squared_error: 0.5253 - val_loss: 0.0749 - val_acc: 0.5794 - val_mean_absolute_error: 0.2106 - val_mean_squared_error: 0.0749
Epoch 7/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.3963 - acc: 0.1630 - mean_absolute_error: 0.4823 - mean_squared_error: 0.3963 - val_loss: 0.0483 - val_acc: 0.4416 - val_mean_absolute_error: 0.1681 - val_mean_squared_error: 0.0483
Epoch 8/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.3052 - acc: 0.1834 - mean_absolute_error: 0.4234 - mean_squared_error: 0.3052 - val_loss: 0.0370 - val_acc: 0.5187 - val_mean_absolute_error: 0.1503 - val_mean_squared_error: 0.0370
Epoch 9/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.2277 - acc: 0.1916 - mean_absolute_error: 0.3666 - mean_squared_error: 0.2277 - val_loss: 0.0417 - val_acc: 0.3762 - val_mean_absolute_error: 0.1643 - val_mean_squared_error: 0.0417
Epoch 10/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.1717 - acc: 0.2190 - mean_absolute_error: 0.3198 - mean_squared_error: 0.1717 - val_loss: 0.0310 - val_acc: 0.5771 - val_mean_absolute_error: 0.1376 - val_mean_squared_error: 0.0310
Epoch 11/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.1319 - acc: 0.2360 - mean_absolute_error: 0.2807 - mean_squared_error: 0.1319 - val_loss: 0.0232 - val_acc: 0.5000 - val_mean_absolute_error: 0.1207 - val_mean_squared_error: 0.0232
Epoch 12/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.1003 - acc: 0.2512 - mean_absolute_error: 0.2456 - mean_squared_error: 0.1003 - val_loss: 0.0197 - val_acc: 0.5210 - val_mean_absolute_error: 0.1109 - val_mean_squared_error: 0.0197
Epoch 13/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0780 - acc: 0.2891 - mean_absolute_error: 0.2170 - mean_squared_error: 0.0780 - val_loss: 0.0141 - val_acc: 0.5047 - val_mean_absolute_error: 0.0925 - val_mean_squared_error: 0.0141
Epoch 14/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0641 - acc: 0.3218 - mean_absolute_error: 0.1968 - mean_squared_error: 0.0641 - val_loss: 0.0142 - val_acc: 0.5164 - val_mean_absolute_error: 0.0930 - val_mean_squared_error: 0.0142
Epoch 15/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0518 - acc: 0.3429 - mean_absolute_error: 0.1773 - mean_squared_error: 0.0518 - val_loss: 0.0114 - val_acc: 0.6449 - val_mean_absolute_error: 0.0831 - val_mean_squared_error: 0.0114
Epoch 16/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0419 - acc: 0.3569 - mean_absolute_error: 0.1595 - mean_squared_error: 0.0419 - val_loss: 0.0094 - val_acc: 0.5234 - val_mean_absolute_error: 0.0756 - val_mean_squared_error: 0.0094
Epoch 17/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0350 - acc: 0.3697 - mean_absolute_error: 0.1453 - mean_squared_error: 0.0350 - val_loss: 0.0088 - val_acc: 0.5140 - val_mean_absolute_error: 0.0728 - val_mean_squared_error: 0.0088
Epoch 18/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0296 - acc: 0.4071 - mean_absolute_error: 0.1343 - mean_squared_error: 0.0296 - val_loss: 0.0080 - val_acc: 0.5444 - val_mean_absolute_error: 0.0695 - val_mean_squared_error: 0.0080
Epoch 19/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0248 - acc: 0.4246 - mean_absolute_error: 0.1228 - mean_squared_error: 0.0248 - val_loss: 0.0074 - val_acc: 0.6542 - val_mean_absolute_error: 0.0666 - val_mean_squared_error: 0.0074
Epoch 20/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0208 - acc: 0.4381 - mean_absolute_error: 0.1127 - mean_squared_error: 0.0208 - val_loss: 0.0068 - val_acc: 0.6939 - val_mean_absolute_error: 0.0640 - val_mean_squared_error: 0.0068
Epoch 21/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0178 - acc: 0.4702 - mean_absolute_error: 0.1042 - mean_squared_error: 0.0178 - val_loss: 0.0054 - val_acc: 0.5701 - val_mean_absolute_error: 0.0564 - val_mean_squared_error: 0.0054
Epoch 22/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0163 - acc: 0.4813 - mean_absolute_error: 0.0994 - mean_squared_error: 0.0163 - val_loss: 0.0071 - val_acc: 0.5140 - val_mean_absolute_error: 0.0637 - val_mean_squared_error: 0.0071
Epoch 23/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0138 - acc: 0.4918 - mean_absolute_error: 0.0916 - mean_squared_error: 0.0138 - val_loss: 0.0053 - val_acc: 0.7079 - val_mean_absolute_error: 0.0554 - val_mean_squared_error: 0.0053
Epoch 24/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0123 - acc: 0.5134 - mean_absolute_error: 0.0868 - mean_squared_error: 0.0123 - val_loss: 0.0045 - val_acc: 0.6121 - val_mean_absolute_error: 0.0511 - val_mean_squared_error: 0.0045
Epoch 25/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0109 - acc: 0.5397 - mean_absolute_error: 0.0816 - mean_squared_error: 0.0109 - val_loss: 0.0044 - val_acc: 0.7500 - val_mean_absolute_error: 0.0505 - val_mean_squared_error: 0.0044
Epoch 26/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0099 - acc: 0.5526 - mean_absolute_error: 0.0779 - mean_squared_error: 0.0099 - val_loss: 0.0047 - val_acc: 0.7220 - val_mean_absolute_error: 0.0531 - val_mean_squared_error: 0.0047
Epoch 27/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0091 - acc: 0.5783 - mean_absolute_error: 0.0746 - mean_squared_error: 0.0091 - val_loss: 0.0043 - val_acc: 0.7266 - val_mean_absolute_error: 0.0494 - val_mean_squared_error: 0.0043
Epoch 28/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0088 - acc: 0.5841 - mean_absolute_error: 0.0735 - mean_squared_error: 0.0088 - val_loss: 0.0040 - val_acc: 0.6542 - val_mean_absolute_error: 0.0477 - val_mean_squared_error: 0.0040
Epoch 29/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0083 - acc: 0.5841 - mean_absolute_error: 0.0706 - mean_squared_error: 0.0083 - val_loss: 0.0038 - val_acc: 0.7547 - val_mean_absolute_error: 0.0464 - val_mean_squared_error: 0.0038
Epoch 30/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0075 - acc: 0.6046 - mean_absolute_error: 0.0679 - mean_squared_error: 0.0075 - val_loss: 0.0043 - val_acc: 0.6916 - val_mean_absolute_error: 0.0503 - val_mean_squared_error: 0.0043
Epoch 31/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0071 - acc: 0.6157 - mean_absolute_error: 0.0655 - mean_squared_error: 0.0071 - val_loss: 0.0033 - val_acc: 0.7734 - val_mean_absolute_error: 0.0430 - val_mean_squared_error: 0.0033
Epoch 32/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0067 - acc: 0.6151 - mean_absolute_error: 0.0639 - mean_squared_error: 0.0067 - val_loss: 0.0034 - val_acc: 0.7710 - val_mean_absolute_error: 0.0441 - val_mean_squared_error: 0.0034
Epoch 33/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0065 - acc: 0.6250 - mean_absolute_error: 0.0629 - mean_squared_error: 0.0065 - val_loss: 0.0036 - val_acc: 0.6869 - val_mean_absolute_error: 0.0455 - val_mean_squared_error: 0.0036
Epoch 34/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0061 - acc: 0.6262 - mean_absolute_error: 0.0608 - mean_squared_error: 0.0061 - val_loss: 0.0037 - val_acc: 0.7500 - val_mean_absolute_error: 0.0455 - val_mean_squared_error: 0.0037
Epoch 35/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0058 - acc: 0.6495 - mean_absolute_error: 0.0595 - mean_squared_error: 0.0058 - val_loss: 0.0031 - val_acc: 0.7313 - val_mean_absolute_error: 0.0425 - val_mean_squared_error: 0.0031
Epoch 36/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0057 - acc: 0.6431 - mean_absolute_error: 0.0584 - mean_squared_error: 0.0057 - val_loss: 0.0036 - val_acc: 0.7477 - val_mean_absolute_error: 0.0451 - val_mean_squared_error: 0.0036
Epoch 37/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0057 - acc: 0.6419 - mean_absolute_error: 0.0588 - mean_squared_error: 0.0057 - val_loss: 0.0036 - val_acc: 0.7266 - val_mean_absolute_error: 0.0458 - val_mean_squared_error: 0.0036
Epoch 38/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0059 - acc: 0.6513 - mean_absolute_error: 0.0597 - mean_squared_error: 0.0059 - val_loss: 0.0042 - val_acc: 0.7196 - val_mean_absolute_error: 0.0502 - val_mean_squared_error: 0.0042
Epoch 39/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0056 - acc: 0.6530 - mean_absolute_error: 0.0581 - mean_squared_error: 0.0056 - val_loss: 0.0032 - val_acc: 0.7477 - val_mean_absolute_error: 0.0423 - val_mean_squared_error: 0.0032
Epoch 40/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0054 - acc: 0.6495 - mean_absolute_error: 0.0566 - mean_squared_error: 0.0054 - val_loss: 0.0032 - val_acc: 0.7523 - val_mean_absolute_error: 0.0425 - val_mean_squared_error: 0.0032
Epoch 41/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0054 - acc: 0.6320 - mean_absolute_error: 0.0574 - mean_squared_error: 0.0054 - val_loss: 0.0039 - val_acc: 0.6986 - val_mean_absolute_error: 0.0480 - val_mean_squared_error: 0.0039
Epoch 42/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0054 - acc: 0.6717 - mean_absolute_error: 0.0572 - mean_squared_error: 0.0054 - val_loss: 0.0039 - val_acc: 0.7477 - val_mean_absolute_error: 0.0456 - val_mean_squared_error: 0.0039
Epoch 43/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0052 - acc: 0.6641 - mean_absolute_error: 0.0558 - mean_squared_error: 0.0052 - val_loss: 0.0040 - val_acc: 0.7523 - val_mean_absolute_error: 0.0487 - val_mean_squared_error: 0.0040
Epoch 44/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0058 - acc: 0.6320 - mean_absolute_error: 0.0586 - mean_squared_error: 0.0058 - val_loss: 0.0045 - val_acc: 0.7126 - val_mean_absolute_error: 0.0510 - val_mean_squared_error: 0.0045
Epoch 45/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0057 - acc: 0.6706 - mean_absolute_error: 0.0581 - mean_squared_error: 0.0057 - val_loss: 0.0029 - val_acc: 0.7570 - val_mean_absolute_error: 0.0403 - val_mean_squared_error: 0.0029
Epoch 46/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0059 - acc: 0.6600 - mean_absolute_error: 0.0592 - mean_squared_error: 0.0059 - val_loss: 0.0039 - val_acc: 0.7336 - val_mean_absolute_error: 0.0472 - val_mean_squared_error: 0.0039
Epoch 47/200
1712/1712 [==============================] - 11s 7ms/step - loss: 0.0055 - acc: 0.6536 - mean_absolute_error: 0.0570 - mean_squared_error: 0.0055 - val_loss: 0.0032 - val_acc: 0.7477 - val_mean_absolute_error: 0.0422 - val_mean_squared_error: 0.0032
Epoch 48/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0057 - acc: 0.6361 - mean_absolute_error: 0.0583 - mean_squared_error: 0.0057 - val_loss: 0.0041 - val_acc: 0.6752 - val_mean_absolute_error: 0.0481 - val_mean_squared_error: 0.0041
Epoch 49/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0054 - acc: 0.6542 - mean_absolute_error: 0.0567 - mean_squared_error: 0.0054 - val_loss: 0.0033 - val_acc: 0.5958 - val_mean_absolute_error: 0.0425 - val_mean_squared_error: 0.0033
Epoch 50/200
1712/1712 [==============================] - 13s 8ms/step - loss: 0.0055 - acc: 0.6133 - mean_absolute_error: 0.0571 - mean_squared_error: 0.0055 - val_loss: 0.0037 - val_acc: 0.7173 - val_mean_absolute_error: 0.0463 - val_mean_squared_error: 0.0037
Epoch 51/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0056 - acc: 0.6577 - mean_absolute_error: 0.0583 - mean_squared_error: 0.0056 - val_loss: 0.0033 - val_acc: 0.6729 - val_mean_absolute_error: 0.0438 - val_mean_squared_error: 0.0033
Epoch 52/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0055 - acc: 0.6548 - mean_absolute_error: 0.0577 - mean_squared_error: 0.0055 - val_loss: 0.0044 - val_acc: 0.2921 - val_mean_absolute_error: 0.0492 - val_mean_squared_error: 0.0044
Epoch 53/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0056 - acc: 0.6373 - mean_absolute_error: 0.0581 - mean_squared_error: 0.0056 - val_loss: 0.0030 - val_acc: 0.7220 - val_mean_absolute_error: 0.0412 - val_mean_squared_error: 0.0030
Epoch 54/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0058 - acc: 0.6384 - mean_absolute_error: 0.0588 - mean_squared_error: 0.0058 - val_loss: 0.0032 - val_acc: 0.7243 - val_mean_absolute_error: 0.0434 - val_mean_squared_error: 0.0032
Epoch 55/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0056 - acc: 0.6735 - mean_absolute_error: 0.0582 - mean_squared_error: 0.0056 - val_loss: 0.0037 - val_acc: 0.7220 - val_mean_absolute_error: 0.0468 - val_mean_squared_error: 0.0037
Epoch 56/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0057 - acc: 0.6910 - mean_absolute_error: 0.0589 - mean_squared_error: 0.0057 - val_loss: 0.0037 - val_acc: 0.6145 - val_mean_absolute_error: 0.0463 - val_mean_squared_error: 0.0037
Epoch 57/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0058 - acc: 0.6379 - mean_absolute_error: 0.0594 - mean_squared_error: 0.0058 - val_loss: 0.0028 - val_acc: 0.7500 - val_mean_absolute_error: 0.0401 - val_mean_squared_error: 0.0028
Epoch 58/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0057 - acc: 0.6741 - mean_absolute_error: 0.0585 - mean_squared_error: 0.0057 - val_loss: 0.0033 - val_acc: 0.7336 - val_mean_absolute_error: 0.0443 - val_mean_squared_error: 0.0033
Epoch 59/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0055 - acc: 0.6437 - mean_absolute_error: 0.0579 - mean_squared_error: 0.0055 - val_loss: 0.0036 - val_acc: 0.6449 - val_mean_absolute_error: 0.0457 - val_mean_squared_error: 0.0036
Epoch 60/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0057 - acc: 0.6419 - mean_absolute_error: 0.0586 - mean_squared_error: 0.0057 - val_loss: 0.0031 - val_acc: 0.7547 - val_mean_absolute_error: 0.0428 - val_mean_squared_error: 0.0031
Epoch 61/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0057 - acc: 0.6162 - mean_absolute_error: 0.0587 - mean_squared_error: 0.0057 - val_loss: 0.0044 - val_acc: 0.7220 - val_mean_absolute_error: 0.0504 - val_mean_squared_error: 0.0044
Epoch 62/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0058 - acc: 0.6583 - mean_absolute_error: 0.0594 - mean_squared_error: 0.0058 - val_loss: 0.0034 - val_acc: 0.7383 - val_mean_absolute_error: 0.0442 - val_mean_squared_error: 0.0034
Epoch 63/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0058 - acc: 0.6624 - mean_absolute_error: 0.0590 - mean_squared_error: 0.0058 - val_loss: 0.0038 - val_acc: 0.7407 - val_mean_absolute_error: 0.0467 - val_mean_squared_error: 0.0038
Epoch 64/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0057 - acc: 0.6472 - mean_absolute_error: 0.0586 - mean_squared_error: 0.0057 - val_loss: 0.0037 - val_acc: 0.6682 - val_mean_absolute_error: 0.0472 - val_mean_squared_error: 0.0037
Epoch 65/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0060 - acc: 0.6326 - mean_absolute_error: 0.0602 - mean_squared_error: 0.0060 - val_loss: 0.0033 - val_acc: 0.7477 - val_mean_absolute_error: 0.0434 - val_mean_squared_error: 0.0033
Epoch 66/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0058 - acc: 0.6449 - mean_absolute_error: 0.0593 - mean_squared_error: 0.0058 - val_loss: 0.0042 - val_acc: 0.6799 - val_mean_absolute_error: 0.0499 - val_mean_squared_error: 0.0042
Epoch 67/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0064 - acc: 0.6688 - mean_absolute_error: 0.0625 - mean_squared_error: 0.0064 - val_loss: 0.0051 - val_acc: 0.7266 - val_mean_absolute_error: 0.0561 - val_mean_squared_error: 0.0051
Epoch 68/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0062 - acc: 0.6530 - mean_absolute_error: 0.0616 - mean_squared_error: 0.0062 - val_loss: 0.0043 - val_acc: 0.7383 - val_mean_absolute_error: 0.0512 - val_mean_squared_error: 0.0043
Epoch 69/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0066 - acc: 0.6852 - mean_absolute_error: 0.0634 - mean_squared_error: 0.0066 - val_loss: 0.0043 - val_acc: 0.6846 - val_mean_absolute_error: 0.0500 - val_mean_squared_error: 0.0043
Epoch 70/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0063 - acc: 0.6525 - mean_absolute_error: 0.0619 - mean_squared_error: 0.0063 - val_loss: 0.0034 - val_acc: 0.7266 - val_mean_absolute_error: 0.0444 - val_mean_squared_error: 0.0034
Epoch 00070: early stopping

(4 Convolutions, 2 FCNs, Mean Squared Error) - RMSProp - No Dropout

In [24]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-4cn-2fc-nodrop-mse-rmsprop.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='rmsprop',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=60, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_9 (Conv2D)            (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_9 (MaxPooling2 (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_10 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_10 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_11 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_11 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
conv2d_12 (Conv2D)           (None, 12, 12, 48)        10416     
_________________________________________________________________
max_pooling2d_12 (MaxPooling (None, 6, 6, 48)          0         
_________________________________________________________________
flatten_3 (Flatten)          (None, 1728)              0         
_________________________________________________________________
dense_5 (Dense)              (None, 100)               172900    
_________________________________________________________________
dense_6 (Dense)              (None, 30)                3030      
=================================================================
Total params: 189,682
Trainable params: 189,682
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0396 - acc: 0.6022 - val_loss: 0.0120 - val_acc: 0.7009
Epoch 2/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0105 - acc: 0.6659 - val_loss: 0.0066 - val_acc: 0.6986
Epoch 3/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0071 - acc: 0.6811 - val_loss: 0.0038 - val_acc: 0.7313
Epoch 4/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0051 - acc: 0.7126 - val_loss: 0.0033 - val_acc: 0.6262
Epoch 5/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0040 - acc: 0.7103 - val_loss: 0.0040 - val_acc: 0.7453
Epoch 6/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0036 - acc: 0.7371 - val_loss: 0.0027 - val_acc: 0.7500
Epoch 7/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0032 - acc: 0.7494 - val_loss: 0.0024 - val_acc: 0.7734
Epoch 8/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0029 - acc: 0.7558 - val_loss: 0.0020 - val_acc: 0.7430
Epoch 9/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0023 - acc: 0.7494 - val_loss: 0.0034 - val_acc: 0.7453
Epoch 10/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0025 - acc: 0.7716 - val_loss: 0.0024 - val_acc: 0.7523
Epoch 11/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0020 - acc: 0.7792 - val_loss: 0.0019 - val_acc: 0.7617
Epoch 12/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0018 - acc: 0.7880 - val_loss: 0.0024 - val_acc: 0.7547
Epoch 13/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0018 - acc: 0.7780 - val_loss: 0.0020 - val_acc: 0.7477
Epoch 14/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0016 - acc: 0.7956 - val_loss: 0.0024 - val_acc: 0.7710
Epoch 15/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0015 - acc: 0.8049 - val_loss: 0.0023 - val_acc: 0.7617
Epoch 16/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0014 - acc: 0.8067 - val_loss: 0.0030 - val_acc: 0.7407
Epoch 17/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0013 - acc: 0.7897 - val_loss: 0.0024 - val_acc: 0.7687
Epoch 18/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0013 - acc: 0.8201 - val_loss: 0.0019 - val_acc: 0.7430
Epoch 19/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0012 - acc: 0.8242 - val_loss: 0.0019 - val_acc: 0.6916
Epoch 20/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0011 - acc: 0.8178 - val_loss: 0.0020 - val_acc: 0.7547
Epoch 21/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0011 - acc: 0.8353 - val_loss: 0.0018 - val_acc: 0.7383
Epoch 22/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0011 - acc: 0.8400 - val_loss: 0.0017 - val_acc: 0.7383
Epoch 23/60
1712/1712 [==============================] - 6s 3ms/step - loss: 9.5006e-04 - acc: 0.8259 - val_loss: 0.0018 - val_acc: 0.7617
Epoch 24/60
1712/1712 [==============================] - 5s 3ms/step - loss: 9.0033e-04 - acc: 0.8417 - val_loss: 0.0020 - val_acc: 0.7477
Epoch 25/60
1712/1712 [==============================] - 6s 3ms/step - loss: 8.9069e-04 - acc: 0.8470 - val_loss: 0.0019 - val_acc: 0.7383
Epoch 26/60
1712/1712 [==============================] - 6s 3ms/step - loss: 8.6969e-04 - acc: 0.8452 - val_loss: 0.0017 - val_acc: 0.6939
Epoch 27/60
1712/1712 [==============================] - 6s 3ms/step - loss: 7.7550e-04 - acc: 0.8388 - val_loss: 0.0019 - val_acc: 0.7617
Epoch 28/60
1712/1712 [==============================] - 5s 3ms/step - loss: 7.4648e-04 - acc: 0.8546 - val_loss: 0.0019 - val_acc: 0.7617
Epoch 29/60
1712/1712 [==============================] - 6s 3ms/step - loss: 7.8386e-04 - acc: 0.8452 - val_loss: 0.0018 - val_acc: 0.7593
Epoch 30/60
1712/1712 [==============================] - 5s 3ms/step - loss: 7.3162e-04 - acc: 0.8440 - val_loss: 0.0019 - val_acc: 0.7523
Epoch 31/60
1712/1712 [==============================] - 6s 3ms/step - loss: 6.8897e-04 - acc: 0.8657 - val_loss: 0.0026 - val_acc: 0.7243
Epoch 32/60
1712/1712 [==============================] - 6s 3ms/step - loss: 6.8972e-04 - acc: 0.8639 - val_loss: 0.0026 - val_acc: 0.7453
Epoch 33/60
1712/1712 [==============================] - 5s 3ms/step - loss: 6.6355e-04 - acc: 0.8674 - val_loss: 0.0018 - val_acc: 0.7547
Epoch 34/60
1712/1712 [==============================] - 6s 3ms/step - loss: 6.3619e-04 - acc: 0.8645 - val_loss: 0.0019 - val_acc: 0.7593
Epoch 35/60
1712/1712 [==============================] - 5s 3ms/step - loss: 6.0894e-04 - acc: 0.8511 - val_loss: 0.0020 - val_acc: 0.7593
Epoch 36/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.7394e-04 - acc: 0.8738 - val_loss: 0.0019 - val_acc: 0.7220
Epoch 37/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.9999e-04 - acc: 0.8534 - val_loss: 0.0018 - val_acc: 0.7664
Epoch 38/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.3534e-04 - acc: 0.8838 - val_loss: 0.0020 - val_acc: 0.7547
Epoch 39/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.7095e-04 - acc: 0.8838 - val_loss: 0.0018 - val_acc: 0.7710
Epoch 40/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.3642e-04 - acc: 0.8674 - val_loss: 0.0022 - val_acc: 0.7360
Epoch 41/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.1019e-04 - acc: 0.8715 - val_loss: 0.0020 - val_acc: 0.7500
Epoch 42/60
1712/1712 [==============================] - 6s 3ms/step - loss: 4.8731e-04 - acc: 0.8709 - val_loss: 0.0020 - val_acc: 0.7593
Epoch 43/60
1712/1712 [==============================] - 6s 3ms/step - loss: 5.0573e-04 - acc: 0.8692 - val_loss: 0.0019 - val_acc: 0.7617
Epoch 44/60
1712/1712 [==============================] - 6s 3ms/step - loss: 4.3093e-04 - acc: 0.8762 - val_loss: 0.0019 - val_acc: 0.7407
Epoch 45/60
1712/1712 [==============================] - 5s 3ms/step - loss: 4.7894e-04 - acc: 0.8803 - val_loss: 0.0020 - val_acc: 0.7523
Epoch 46/60
1712/1712 [==============================] - 6s 3ms/step - loss: 4.7968e-04 - acc: 0.8820 - val_loss: 0.0020 - val_acc: 0.7593
Epoch 00046: early stopping

(4 Convolutions, 2 FCNs, Mean Squared Error) - RMSProp - Dropout

In [28]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-4cn-2fc-drop-mse-rmsprop.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(Dropout(0.5))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='rmsprop',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=60, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_25 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_25 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_26 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_26 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_27 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_27 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
conv2d_28 (Conv2D)           (None, 12, 12, 48)        10416     
_________________________________________________________________
max_pooling2d_28 (MaxPooling (None, 6, 6, 48)          0         
_________________________________________________________________
dropout_4 (Dropout)          (None, 6, 6, 48)          0         
_________________________________________________________________
flatten_7 (Flatten)          (None, 1728)              0         
_________________________________________________________________
dense_13 (Dense)             (None, 100)               172900    
_________________________________________________________________
dense_14 (Dense)             (None, 30)                3030      
=================================================================
Total params: 189,682
Trainable params: 189,682
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0219 - acc: 0.5502 - mean_absolute_error: 0.1057 - mean_squared_error: 0.0219 - val_loss: 0.0114 - val_acc: 0.6963 - val_mean_absolute_error: 0.0856 - val_mean_squared_error: 0.0114
Epoch 2/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0085 - acc: 0.6595 - mean_absolute_error: 0.0698 - mean_squared_error: 0.0085 - val_loss: 0.0094 - val_acc: 0.7079 - val_mean_absolute_error: 0.0785 - val_mean_squared_error: 0.0094
Epoch 3/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0073 - acc: 0.6764 - mean_absolute_error: 0.0628 - mean_squared_error: 0.0073 - val_loss: 0.0034 - val_acc: 0.7173 - val_mean_absolute_error: 0.0430 - val_mean_squared_error: 0.0034
Epoch 4/60
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0052 - acc: 0.6945 - mean_absolute_error: 0.0543 - mean_squared_error: 0.0052 - val_loss: 0.0033 - val_acc: 0.7126 - val_mean_absolute_error: 0.0443 - val_mean_squared_error: 0.0033
Epoch 5/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0040 - acc: 0.6998 - mean_absolute_error: 0.0469 - mean_squared_error: 0.0040 - val_loss: 0.0034 - val_acc: 0.6846 - val_mean_absolute_error: 0.0448 - val_mean_squared_error: 0.0034
Epoch 6/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0044 - acc: 0.7202 - mean_absolute_error: 0.0496 - mean_squared_error: 0.0044 - val_loss: 0.0026 - val_acc: 0.7033 - val_mean_absolute_error: 0.0372 - val_mean_squared_error: 0.0026
Epoch 7/60
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0037 - acc: 0.7155 - mean_absolute_error: 0.0450 - mean_squared_error: 0.0037 - val_loss: 0.0021 - val_acc: 0.7196 - val_mean_absolute_error: 0.0334 - val_mean_squared_error: 0.0021
Epoch 8/60
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0031 - acc: 0.7179 - mean_absolute_error: 0.0420 - mean_squared_error: 0.0031 - val_loss: 0.0022 - val_acc: 0.7313 - val_mean_absolute_error: 0.0343 - val_mean_squared_error: 0.0022
Epoch 9/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0030 - acc: 0.7296 - mean_absolute_error: 0.0409 - mean_squared_error: 0.0030 - val_loss: 0.0021 - val_acc: 0.7477 - val_mean_absolute_error: 0.0333 - val_mean_squared_error: 0.0021
Epoch 10/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0029 - acc: 0.7354 - mean_absolute_error: 0.0401 - mean_squared_error: 0.0029 - val_loss: 0.0029 - val_acc: 0.7383 - val_mean_absolute_error: 0.0416 - val_mean_squared_error: 0.0029
Epoch 11/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0029 - acc: 0.7336 - mean_absolute_error: 0.0401 - mean_squared_error: 0.0029 - val_loss: 0.0018 - val_acc: 0.7453 - val_mean_absolute_error: 0.0305 - val_mean_squared_error: 0.0018
Epoch 12/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0024 - acc: 0.7436 - mean_absolute_error: 0.0365 - mean_squared_error: 0.0024 - val_loss: 0.0030 - val_acc: 0.7593 - val_mean_absolute_error: 0.0402 - val_mean_squared_error: 0.0030
Epoch 13/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0024 - acc: 0.7430 - mean_absolute_error: 0.0369 - mean_squared_error: 0.0024 - val_loss: 0.0020 - val_acc: 0.7523 - val_mean_absolute_error: 0.0325 - val_mean_squared_error: 0.0020
Epoch 14/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0023 - acc: 0.7529 - mean_absolute_error: 0.0357 - mean_squared_error: 0.0023 - val_loss: 0.0025 - val_acc: 0.7640 - val_mean_absolute_error: 0.0389 - val_mean_squared_error: 0.0025
Epoch 15/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7494 - mean_absolute_error: 0.0350 - mean_squared_error: 0.0022 - val_loss: 0.0016 - val_acc: 0.7593 - val_mean_absolute_error: 0.0285 - val_mean_squared_error: 0.0016
Epoch 16/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0021 - acc: 0.7535 - mean_absolute_error: 0.0337 - mean_squared_error: 0.0021 - val_loss: 0.0023 - val_acc: 0.7593 - val_mean_absolute_error: 0.0345 - val_mean_squared_error: 0.0023
Epoch 17/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0020 - acc: 0.7558 - mean_absolute_error: 0.0336 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7617 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 18/60
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0018 - acc: 0.7704 - mean_absolute_error: 0.0320 - mean_squared_error: 0.0018 - val_loss: 0.0017 - val_acc: 0.7593 - val_mean_absolute_error: 0.0303 - val_mean_squared_error: 0.0017
Epoch 19/60
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0018 - acc: 0.7722 - mean_absolute_error: 0.0321 - mean_squared_error: 0.0018 - val_loss: 0.0016 - val_acc: 0.7477 - val_mean_absolute_error: 0.0295 - val_mean_squared_error: 0.0016
Epoch 20/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0017 - acc: 0.7739 - mean_absolute_error: 0.0307 - mean_squared_error: 0.0017 - val_loss: 0.0020 - val_acc: 0.7336 - val_mean_absolute_error: 0.0338 - val_mean_squared_error: 0.0020
Epoch 21/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0017 - acc: 0.7757 - mean_absolute_error: 0.0303 - mean_squared_error: 0.0017 - val_loss: 0.0019 - val_acc: 0.7734 - val_mean_absolute_error: 0.0326 - val_mean_squared_error: 0.0019
Epoch 22/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0016 - acc: 0.7775 - mean_absolute_error: 0.0299 - mean_squared_error: 0.0016 - val_loss: 0.0019 - val_acc: 0.7734 - val_mean_absolute_error: 0.0332 - val_mean_squared_error: 0.0019
Epoch 23/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0015 - acc: 0.7804 - mean_absolute_error: 0.0290 - mean_squared_error: 0.0015 - val_loss: 0.0016 - val_acc: 0.7500 - val_mean_absolute_error: 0.0290 - val_mean_squared_error: 0.0016
Epoch 24/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0015 - acc: 0.7751 - mean_absolute_error: 0.0283 - mean_squared_error: 0.0015 - val_loss: 0.0023 - val_acc: 0.7687 - val_mean_absolute_error: 0.0360 - val_mean_squared_error: 0.0023
Epoch 25/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0014 - acc: 0.7780 - mean_absolute_error: 0.0280 - mean_squared_error: 0.0014 - val_loss: 0.0014 - val_acc: 0.7827 - val_mean_absolute_error: 0.0265 - val_mean_squared_error: 0.0014
Epoch 26/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0014 - acc: 0.7880 - mean_absolute_error: 0.0278 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7804 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 27/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0013 - acc: 0.7792 - mean_absolute_error: 0.0270 - mean_squared_error: 0.0013 - val_loss: 0.0018 - val_acc: 0.7804 - val_mean_absolute_error: 0.0305 - val_mean_squared_error: 0.0018
Epoch 28/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0013 - acc: 0.7886 - mean_absolute_error: 0.0265 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7827 - val_mean_absolute_error: 0.0270 - val_mean_squared_error: 0.0014
Epoch 29/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.7681 - mean_absolute_error: 0.0261 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_acc: 0.7664 - val_mean_absolute_error: 0.0258 - val_mean_squared_error: 0.0013
Epoch 30/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7862 - mean_absolute_error: 0.0258 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0261 - val_mean_squared_error: 0.0014
Epoch 31/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7950 - mean_absolute_error: 0.0258 - mean_squared_error: 0.0012 - val_loss: 0.0015 - val_acc: 0.7921 - val_mean_absolute_error: 0.0276 - val_mean_squared_error: 0.0015
Epoch 32/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0012 - acc: 0.7850 - mean_absolute_error: 0.0255 - mean_squared_error: 0.0012 - val_loss: 0.0015 - val_acc: 0.7850 - val_mean_absolute_error: 0.0277 - val_mean_squared_error: 0.0015
Epoch 33/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7961 - mean_absolute_error: 0.0251 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0268 - val_mean_squared_error: 0.0014
Epoch 34/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0011 - acc: 0.7950 - mean_absolute_error: 0.0252 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7664 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0014
Epoch 35/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0011 - acc: 0.7897 - mean_absolute_error: 0.0250 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7664 - val_mean_absolute_error: 0.0270 - val_mean_squared_error: 0.0014
Epoch 36/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7985 - mean_absolute_error: 0.0249 - mean_squared_error: 0.0011 - val_loss: 0.0015 - val_acc: 0.7757 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 37/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.8014 - mean_absolute_error: 0.0248 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0264 - val_mean_squared_error: 0.0014
Epoch 38/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0011 - acc: 0.7915 - mean_absolute_error: 0.0244 - mean_squared_error: 0.0011 - val_loss: 0.0015 - val_acc: 0.7874 - val_mean_absolute_error: 0.0282 - val_mean_squared_error: 0.0015
Epoch 39/60
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0011 - acc: 0.7874 - mean_absolute_error: 0.0246 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7944 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0013
Epoch 40/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0011 - acc: 0.7868 - mean_absolute_error: 0.0243 - mean_squared_error: 0.0011 - val_loss: 0.0015 - val_acc: 0.7780 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0015
Epoch 41/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7991 - mean_absolute_error: 0.0244 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7780 - val_mean_absolute_error: 0.0267 - val_mean_squared_error: 0.0014
Epoch 42/60
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0010 - acc: 0.8072 - mean_absolute_error: 0.0242 - mean_squared_error: 0.0010 - val_loss: 0.0014 - val_acc: 0.7921 - val_mean_absolute_error: 0.0265 - val_mean_squared_error: 0.0014
Epoch 43/60
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0010 - acc: 0.8067 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0016 - val_acc: 0.8037 - val_mean_absolute_error: 0.0286 - val_mean_squared_error: 0.0016
Epoch 44/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.7956 - mean_absolute_error: 0.0241 - mean_squared_error: 0.0010 - val_loss: 0.0016 - val_acc: 0.7780 - val_mean_absolute_error: 0.0291 - val_mean_squared_error: 0.0016
Epoch 45/60
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0010 - acc: 0.8183 - mean_absolute_error: 0.0238 - mean_squared_error: 0.0010 - val_loss: 0.0014 - val_acc: 0.7991 - val_mean_absolute_error: 0.0260 - val_mean_squared_error: 0.0014
Epoch 46/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0010 - acc: 0.7996 - mean_absolute_error: 0.0242 - mean_squared_error: 0.0010 - val_loss: 0.0015 - val_acc: 0.7874 - val_mean_absolute_error: 0.0274 - val_mean_squared_error: 0.0015
Epoch 47/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0010 - acc: 0.7979 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0010 - val_loss: 0.0015 - val_acc: 0.7757 - val_mean_absolute_error: 0.0274 - val_mean_squared_error: 0.0015
Epoch 48/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0010 - acc: 0.7932 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7921 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0013
Epoch 49/60
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0010 - acc: 0.8049 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0015 - val_acc: 0.8037 - val_mean_absolute_error: 0.0276 - val_mean_squared_error: 0.0015
Epoch 50/60
1712/1712 [==============================] - 8s 5ms/step - loss: 9.7898e-04 - acc: 0.8037 - mean_absolute_error: 0.0234 - mean_squared_error: 9.7898e-04 - val_loss: 0.0013 - val_acc: 0.7710 - val_mean_absolute_error: 0.0260 - val_mean_squared_error: 0.0013
Epoch 00050: early stopping

(4 Convolutions, 2 FCNs, Mean Squared Error) - Adam - No Dropout

In [47]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-4cn-2fc-nodrop-mse-adam.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='adam',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=200, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_45 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_45 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_46 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_46 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_47 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_47 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
conv2d_48 (Conv2D)           (None, 12, 12, 48)        10416     
_________________________________________________________________
max_pooling2d_48 (MaxPooling (None, 6, 6, 48)          0         
_________________________________________________________________
flatten_12 (Flatten)         (None, 1728)              0         
_________________________________________________________________
dense_23 (Dense)             (None, 100)               172900    
_________________________________________________________________
dense_24 (Dense)             (None, 30)                3030      
=================================================================
Total params: 189,682
Trainable params: 189,682
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0189 - acc: 0.5923 - mean_absolute_error: 0.0885 - mean_squared_error: 0.0189 - val_loss: 0.0053 - val_acc: 0.6355 - val_mean_absolute_error: 0.0544 - val_mean_squared_error: 0.0053
Epoch 2/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0043 - acc: 0.6869 - mean_absolute_error: 0.0484 - mean_squared_error: 0.0043 - val_loss: 0.0037 - val_acc: 0.6986 - val_mean_absolute_error: 0.0452 - val_mean_squared_error: 0.0037
Epoch 3/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0034 - acc: 0.6986 - mean_absolute_error: 0.0434 - mean_squared_error: 0.0034 - val_loss: 0.0036 - val_acc: 0.7009 - val_mean_absolute_error: 0.0452 - val_mean_squared_error: 0.0036
Epoch 4/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0029 - acc: 0.7097 - mean_absolute_error: 0.0392 - mean_squared_error: 0.0029 - val_loss: 0.0028 - val_acc: 0.7220 - val_mean_absolute_error: 0.0390 - val_mean_squared_error: 0.0028
Epoch 5/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0024 - acc: 0.7249 - mean_absolute_error: 0.0361 - mean_squared_error: 0.0024 - val_loss: 0.0025 - val_acc: 0.7266 - val_mean_absolute_error: 0.0367 - val_mean_squared_error: 0.0025
Epoch 6/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0022 - acc: 0.7395 - mean_absolute_error: 0.0342 - mean_squared_error: 0.0022 - val_loss: 0.0023 - val_acc: 0.7570 - val_mean_absolute_error: 0.0349 - val_mean_squared_error: 0.0023
Epoch 7/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0020 - acc: 0.7447 - mean_absolute_error: 0.0321 - mean_squared_error: 0.0020 - val_loss: 0.0021 - val_acc: 0.7547 - val_mean_absolute_error: 0.0334 - val_mean_squared_error: 0.0021
Epoch 8/200
1712/1712 [==============================] - 5s 3ms/step - loss: 0.0018 - acc: 0.7576 - mean_absolute_error: 0.0307 - mean_squared_error: 0.0018 - val_loss: 0.0020 - val_acc: 0.7477 - val_mean_absolute_error: 0.0324 - val_mean_squared_error: 0.0020
Epoch 9/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0017 - acc: 0.7553 - mean_absolute_error: 0.0299 - mean_squared_error: 0.0017 - val_loss: 0.0020 - val_acc: 0.7523 - val_mean_absolute_error: 0.0322 - val_mean_squared_error: 0.0020
Epoch 10/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0016 - acc: 0.7582 - mean_absolute_error: 0.0287 - mean_squared_error: 0.0016 - val_loss: 0.0019 - val_acc: 0.7710 - val_mean_absolute_error: 0.0312 - val_mean_squared_error: 0.0019
Epoch 11/200
1712/1712 [==============================] - 6s 3ms/step - loss: 0.0016 - acc: 0.7710 - mean_absolute_error: 0.0286 - mean_squared_error: 0.0016 - val_loss: 0.0020 - val_acc: 0.7664 - val_mean_absolute_error: 0.0321 - val_mean_squared_error: 0.0020
Epoch 12/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0014 - acc: 0.7815 - mean_absolute_error: 0.0272 - mean_squared_error: 0.0014 - val_loss: 0.0018 - val_acc: 0.7593 - val_mean_absolute_error: 0.0303 - val_mean_squared_error: 0.0018
Epoch 13/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0014 - acc: 0.7868 - mean_absolute_error: 0.0267 - mean_squared_error: 0.0014 - val_loss: 0.0018 - val_acc: 0.7687 - val_mean_absolute_error: 0.0306 - val_mean_squared_error: 0.0018
Epoch 14/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0013 - acc: 0.7880 - mean_absolute_error: 0.0262 - mean_squared_error: 0.0013 - val_loss: 0.0017 - val_acc: 0.7780 - val_mean_absolute_error: 0.0296 - val_mean_squared_error: 0.0017
Epoch 15/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0012 - acc: 0.7973 - mean_absolute_error: 0.0254 - mean_squared_error: 0.0012 - val_loss: 0.0017 - val_acc: 0.7850 - val_mean_absolute_error: 0.0291 - val_mean_squared_error: 0.0017
Epoch 16/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0012 - acc: 0.7961 - mean_absolute_error: 0.0252 - mean_squared_error: 0.0012 - val_loss: 0.0017 - val_acc: 0.7780 - val_mean_absolute_error: 0.0293 - val_mean_squared_error: 0.0017
Epoch 17/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0011 - acc: 0.7996 - mean_absolute_error: 0.0244 - mean_squared_error: 0.0011 - val_loss: 0.0017 - val_acc: 0.7967 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 18/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0011 - acc: 0.8026 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0011 - val_loss: 0.0017 - val_acc: 0.7874 - val_mean_absolute_error: 0.0291 - val_mean_squared_error: 0.0017
Epoch 19/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0010 - acc: 0.8078 - mean_absolute_error: 0.0235 - mean_squared_error: 0.0010 - val_loss: 0.0016 - val_acc: 0.7734 - val_mean_absolute_error: 0.0286 - val_mean_squared_error: 0.0016
Epoch 20/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0010 - acc: 0.8055 - mean_absolute_error: 0.0232 - mean_squared_error: 0.0010 - val_loss: 0.0016 - val_acc: 0.7874 - val_mean_absolute_error: 0.0284 - val_mean_squared_error: 0.0016
Epoch 21/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.7206e-04 - acc: 0.8096 - mean_absolute_error: 0.0228 - mean_squared_error: 9.7206e-04 - val_loss: 0.0016 - val_acc: 0.7944 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0016
Epoch 22/200
1712/1712 [==============================] - 8s 5ms/step - loss: 9.3792e-04 - acc: 0.8148 - mean_absolute_error: 0.0225 - mean_squared_error: 9.3792e-04 - val_loss: 0.0016 - val_acc: 0.8014 - val_mean_absolute_error: 0.0286 - val_mean_squared_error: 0.0016
Epoch 23/200
1712/1712 [==============================] - 8s 5ms/step - loss: 9.1799e-04 - acc: 0.8218 - mean_absolute_error: 0.0222 - mean_squared_error: 9.1799e-04 - val_loss: 0.0016 - val_acc: 0.8084 - val_mean_absolute_error: 0.0279 - val_mean_squared_error: 0.0016
Epoch 24/200
1712/1712 [==============================] - 9s 5ms/step - loss: 8.6173e-04 - acc: 0.8096 - mean_absolute_error: 0.0215 - mean_squared_error: 8.6173e-04 - val_loss: 0.0016 - val_acc: 0.8037 - val_mean_absolute_error: 0.0288 - val_mean_squared_error: 0.0016
Epoch 25/200
1712/1712 [==============================] - 10s 6ms/step - loss: 8.8553e-04 - acc: 0.8201 - mean_absolute_error: 0.0221 - mean_squared_error: 8.8553e-04 - val_loss: 0.0016 - val_acc: 0.7804 - val_mean_absolute_error: 0.0286 - val_mean_squared_error: 0.0016
Epoch 26/200
1712/1712 [==============================] - 9s 5ms/step - loss: 8.0995e-04 - acc: 0.8312 - mean_absolute_error: 0.0209 - mean_squared_error: 8.0995e-04 - val_loss: 0.0015 - val_acc: 0.7967 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 27/200
1712/1712 [==============================] - 10s 6ms/step - loss: 7.8728e-04 - acc: 0.8300 - mean_absolute_error: 0.0206 - mean_squared_error: 7.8728e-04 - val_loss: 0.0015 - val_acc: 0.7991 - val_mean_absolute_error: 0.0279 - val_mean_squared_error: 0.0015
Epoch 28/200
1712/1712 [==============================] - 10s 6ms/step - loss: 7.8353e-04 - acc: 0.8324 - mean_absolute_error: 0.0207 - mean_squared_error: 7.8353e-04 - val_loss: 0.0016 - val_acc: 0.7944 - val_mean_absolute_error: 0.0283 - val_mean_squared_error: 0.0016
Epoch 29/200
1712/1712 [==============================] - 9s 5ms/step - loss: 7.3702e-04 - acc: 0.8242 - mean_absolute_error: 0.0201 - mean_squared_error: 7.3702e-04 - val_loss: 0.0016 - val_acc: 0.7827 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0016
Epoch 30/200
1712/1712 [==============================] - 9s 5ms/step - loss: 7.2384e-04 - acc: 0.8382 - mean_absolute_error: 0.0200 - mean_squared_error: 7.2384e-04 - val_loss: 0.0015 - val_acc: 0.7967 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 31/200
1712/1712 [==============================] - 9s 5ms/step - loss: 6.8344e-04 - acc: 0.8359 - mean_absolute_error: 0.0194 - mean_squared_error: 6.8344e-04 - val_loss: 0.0016 - val_acc: 0.7967 - val_mean_absolute_error: 0.0280 - val_mean_squared_error: 0.0016
Epoch 32/200
1712/1712 [==============================] - 9s 5ms/step - loss: 6.6134e-04 - acc: 0.8364 - mean_absolute_error: 0.0191 - mean_squared_error: 6.6134e-04 - val_loss: 0.0015 - val_acc: 0.8107 - val_mean_absolute_error: 0.0279 - val_mean_squared_error: 0.0015
Epoch 33/200
1712/1712 [==============================] - 9s 5ms/step - loss: 6.4378e-04 - acc: 0.8440 - mean_absolute_error: 0.0189 - mean_squared_error: 6.4378e-04 - val_loss: 0.0015 - val_acc: 0.8014 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 34/200
1712/1712 [==============================] - 9s 6ms/step - loss: 6.2519e-04 - acc: 0.8440 - mean_absolute_error: 0.0186 - mean_squared_error: 6.2519e-04 - val_loss: 0.0016 - val_acc: 0.7944 - val_mean_absolute_error: 0.0282 - val_mean_squared_error: 0.0016
Epoch 35/200
1712/1712 [==============================] - 9s 5ms/step - loss: 6.1043e-04 - acc: 0.8429 - mean_absolute_error: 0.0184 - mean_squared_error: 6.1043e-04 - val_loss: 0.0015 - val_acc: 0.7827 - val_mean_absolute_error: 0.0278 - val_mean_squared_error: 0.0015
Epoch 36/200
1712/1712 [==============================] - 8s 5ms/step - loss: 5.8889e-04 - acc: 0.8534 - mean_absolute_error: 0.0182 - mean_squared_error: 5.8889e-04 - val_loss: 0.0015 - val_acc: 0.7944 - val_mean_absolute_error: 0.0276 - val_mean_squared_error: 0.0015
Epoch 37/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.7031e-04 - acc: 0.8405 - mean_absolute_error: 0.0178 - mean_squared_error: 5.7031e-04 - val_loss: 0.0016 - val_acc: 0.7757 - val_mean_absolute_error: 0.0280 - val_mean_squared_error: 0.0016
Epoch 38/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.5302e-04 - acc: 0.8429 - mean_absolute_error: 0.0176 - mean_squared_error: 5.5302e-04 - val_loss: 0.0016 - val_acc: 0.7944 - val_mean_absolute_error: 0.0280 - val_mean_squared_error: 0.0016
Epoch 39/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.3459e-04 - acc: 0.8522 - mean_absolute_error: 0.0174 - mean_squared_error: 5.3459e-04 - val_loss: 0.0016 - val_acc: 0.7897 - val_mean_absolute_error: 0.0286 - val_mean_squared_error: 0.0016
Epoch 40/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.2360e-04 - acc: 0.8616 - mean_absolute_error: 0.0172 - mean_squared_error: 5.2360e-04 - val_loss: 0.0015 - val_acc: 0.7827 - val_mean_absolute_error: 0.0277 - val_mean_squared_error: 0.0015
Epoch 41/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.0612e-04 - acc: 0.8557 - mean_absolute_error: 0.0169 - mean_squared_error: 5.0612e-04 - val_loss: 0.0016 - val_acc: 0.7991 - val_mean_absolute_error: 0.0285 - val_mean_squared_error: 0.0016
Epoch 42/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.2999e-04 - acc: 0.8505 - mean_absolute_error: 0.0174 - mean_squared_error: 5.2999e-04 - val_loss: 0.0016 - val_acc: 0.7874 - val_mean_absolute_error: 0.0289 - val_mean_squared_error: 0.0016
Epoch 43/200
1712/1712 [==============================] - 9s 5ms/step - loss: 5.1427e-04 - acc: 0.8575 - mean_absolute_error: 0.0172 - mean_squared_error: 5.1427e-04 - val_loss: 0.0016 - val_acc: 0.7921 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0016
Epoch 44/200
1712/1712 [==============================] - 9s 5ms/step - loss: 4.7716e-04 - acc: 0.8610 - mean_absolute_error: 0.0165 - mean_squared_error: 4.7716e-04 - val_loss: 0.0016 - val_acc: 0.7991 - val_mean_absolute_error: 0.0283 - val_mean_squared_error: 0.0016
Epoch 45/200
1712/1712 [==============================] - 9s 5ms/step - loss: 4.6103e-04 - acc: 0.8686 - mean_absolute_error: 0.0163 - mean_squared_error: 4.6103e-04 - val_loss: 0.0016 - val_acc: 0.7921 - val_mean_absolute_error: 0.0280 - val_mean_squared_error: 0.0016
Epoch 00045: early stopping

(4 Convolutions, 2 FCNs, Mean Squared Error) - Adam - Dropout

In [38]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-4cn-2fc-drop-mse-adam.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1
model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(Dropout(0.5))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100
model.add(Dense(100))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='adam',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=200, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_41 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_41 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
conv2d_42 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_42 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
conv2d_43 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_43 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
conv2d_44 (Conv2D)           (None, 12, 12, 48)        10416     
_________________________________________________________________
max_pooling2d_44 (MaxPooling (None, 6, 6, 48)          0         
_________________________________________________________________
dropout_8 (Dropout)          (None, 6, 6, 48)          0         
_________________________________________________________________
flatten_11 (Flatten)         (None, 1728)              0         
_________________________________________________________________
dense_21 (Dense)             (None, 100)               172900    
_________________________________________________________________
dense_22 (Dense)             (None, 30)                3030      
=================================================================
Total params: 189,682
Trainable params: 189,682
Non-trainable params: 0
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0192 - acc: 0.5286 - mean_absolute_error: 0.0946 - mean_squared_error: 0.0192 - val_loss: 0.0041 - val_acc: 0.7009 - val_mean_absolute_error: 0.0475 - val_mean_squared_error: 0.0041
Epoch 2/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0052 - acc: 0.6630 - mean_absolute_error: 0.0549 - mean_squared_error: 0.0052 - val_loss: 0.0037 - val_acc: 0.7009 - val_mean_absolute_error: 0.0448 - val_mean_squared_error: 0.0037
Epoch 3/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0043 - acc: 0.6811 - mean_absolute_error: 0.0493 - mean_squared_error: 0.0043 - val_loss: 0.0033 - val_acc: 0.7103 - val_mean_absolute_error: 0.0417 - val_mean_squared_error: 0.0033
Epoch 4/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0039 - acc: 0.6846 - mean_absolute_error: 0.0464 - mean_squared_error: 0.0039 - val_loss: 0.0030 - val_acc: 0.7150 - val_mean_absolute_error: 0.0404 - val_mean_squared_error: 0.0030
Epoch 5/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0035 - acc: 0.6963 - mean_absolute_error: 0.0442 - mean_squared_error: 0.0035 - val_loss: 0.0026 - val_acc: 0.7150 - val_mean_absolute_error: 0.0366 - val_mean_squared_error: 0.0026
Epoch 6/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0031 - acc: 0.7039 - mean_absolute_error: 0.0414 - mean_squared_error: 0.0031 - val_loss: 0.0023 - val_acc: 0.7266 - val_mean_absolute_error: 0.0344 - val_mean_squared_error: 0.0023
Epoch 7/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0029 - acc: 0.7126 - mean_absolute_error: 0.0398 - mean_squared_error: 0.0029 - val_loss: 0.0021 - val_acc: 0.7220 - val_mean_absolute_error: 0.0332 - val_mean_squared_error: 0.0021
Epoch 8/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0027 - acc: 0.7231 - mean_absolute_error: 0.0386 - mean_squared_error: 0.0027 - val_loss: 0.0022 - val_acc: 0.7313 - val_mean_absolute_error: 0.0339 - val_mean_squared_error: 0.0022
Epoch 9/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0025 - acc: 0.7161 - mean_absolute_error: 0.0370 - mean_squared_error: 0.0025 - val_loss: 0.0019 - val_acc: 0.7290 - val_mean_absolute_error: 0.0314 - val_mean_squared_error: 0.0019
Epoch 10/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0024 - acc: 0.7126 - mean_absolute_error: 0.0362 - mean_squared_error: 0.0024 - val_loss: 0.0019 - val_acc: 0.7407 - val_mean_absolute_error: 0.0308 - val_mean_squared_error: 0.0019
Epoch 11/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7249 - mean_absolute_error: 0.0349 - mean_squared_error: 0.0022 - val_loss: 0.0018 - val_acc: 0.7313 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0018
Epoch 12/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0022 - acc: 0.7307 - mean_absolute_error: 0.0344 - mean_squared_error: 0.0022 - val_loss: 0.0021 - val_acc: 0.7430 - val_mean_absolute_error: 0.0330 - val_mean_squared_error: 0.0021
Epoch 13/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0020 - acc: 0.7377 - mean_absolute_error: 0.0333 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7453 - val_mean_absolute_error: 0.0294 - val_mean_squared_error: 0.0017
Epoch 14/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0020 - acc: 0.7231 - mean_absolute_error: 0.0329 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7570 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 15/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0020 - acc: 0.7459 - mean_absolute_error: 0.0330 - mean_squared_error: 0.0020 - val_loss: 0.0016 - val_acc: 0.7453 - val_mean_absolute_error: 0.0284 - val_mean_squared_error: 0.0016
Epoch 16/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7488 - mean_absolute_error: 0.0314 - mean_squared_error: 0.0018 - val_loss: 0.0017 - val_acc: 0.7477 - val_mean_absolute_error: 0.0295 - val_mean_squared_error: 0.0017
Epoch 17/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0018 - acc: 0.7395 - mean_absolute_error: 0.0313 - mean_squared_error: 0.0018 - val_loss: 0.0016 - val_acc: 0.7453 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0016
Epoch 18/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0017 - acc: 0.7506 - mean_absolute_error: 0.0307 - mean_squared_error: 0.0017 - val_loss: 0.0016 - val_acc: 0.7523 - val_mean_absolute_error: 0.0279 - val_mean_squared_error: 0.0016
Epoch 19/200
1712/1712 [==============================] - 11s 7ms/step - loss: 0.0017 - acc: 0.7488 - mean_absolute_error: 0.0304 - mean_squared_error: 0.0017 - val_loss: 0.0016 - val_acc: 0.7593 - val_mean_absolute_error: 0.0281 - val_mean_squared_error: 0.0016
Epoch 20/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7436 - mean_absolute_error: 0.0301 - mean_squared_error: 0.0017 - val_loss: 0.0015 - val_acc: 0.7734 - val_mean_absolute_error: 0.0275 - val_mean_squared_error: 0.0015
Epoch 21/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0016 - acc: 0.7611 - mean_absolute_error: 0.0293 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7500 - val_mean_absolute_error: 0.0275 - val_mean_squared_error: 0.0015
Epoch 22/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0016 - acc: 0.7652 - mean_absolute_error: 0.0294 - mean_squared_error: 0.0016 - val_loss: 0.0015 - val_acc: 0.7453 - val_mean_absolute_error: 0.0279 - val_mean_squared_error: 0.0015
Epoch 23/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0015 - acc: 0.7564 - mean_absolute_error: 0.0289 - mean_squared_error: 0.0015 - val_loss: 0.0015 - val_acc: 0.7640 - val_mean_absolute_error: 0.0269 - val_mean_squared_error: 0.0015
Epoch 24/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0015 - acc: 0.7658 - mean_absolute_error: 0.0289 - mean_squared_error: 0.0015 - val_loss: 0.0015 - val_acc: 0.7734 - val_mean_absolute_error: 0.0273 - val_mean_squared_error: 0.0015
Epoch 25/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0015 - acc: 0.7652 - mean_absolute_error: 0.0285 - mean_squared_error: 0.0015 - val_loss: 0.0014 - val_acc: 0.7500 - val_mean_absolute_error: 0.0269 - val_mean_squared_error: 0.0014
Epoch 26/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0015 - acc: 0.7757 - mean_absolute_error: 0.0282 - mean_squared_error: 0.0015 - val_loss: 0.0014 - val_acc: 0.7664 - val_mean_absolute_error: 0.0267 - val_mean_squared_error: 0.0014
Epoch 27/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0014 - acc: 0.7634 - mean_absolute_error: 0.0276 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7687 - val_mean_absolute_error: 0.0271 - val_mean_squared_error: 0.0015
Epoch 28/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0015 - acc: 0.7704 - mean_absolute_error: 0.0281 - mean_squared_error: 0.0015 - val_loss: 0.0014 - val_acc: 0.7664 - val_mean_absolute_error: 0.0264 - val_mean_squared_error: 0.0014
Epoch 29/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0014 - acc: 0.7792 - mean_absolute_error: 0.0272 - mean_squared_error: 0.0014 - val_loss: 0.0015 - val_acc: 0.7617 - val_mean_absolute_error: 0.0271 - val_mean_squared_error: 0.0015
Epoch 30/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0013 - acc: 0.7804 - mean_absolute_error: 0.0270 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7687 - val_mean_absolute_error: 0.0268 - val_mean_squared_error: 0.0014
Epoch 31/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0013 - acc: 0.7798 - mean_absolute_error: 0.0270 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7710 - val_mean_absolute_error: 0.0268 - val_mean_squared_error: 0.0014
Epoch 32/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0013 - acc: 0.7704 - mean_absolute_error: 0.0266 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0258 - val_mean_squared_error: 0.0014
Epoch 33/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0013 - acc: 0.7716 - mean_absolute_error: 0.0264 - mean_squared_error: 0.0013 - val_loss: 0.0014 - val_acc: 0.7921 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0014
Epoch 34/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0012 - acc: 0.7810 - mean_absolute_error: 0.0259 - mean_squared_error: 0.0012 - val_loss: 0.0014 - val_acc: 0.7757 - val_mean_absolute_error: 0.0265 - val_mean_squared_error: 0.0014
Epoch 35/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0013 - acc: 0.7862 - mean_absolute_error: 0.0260 - mean_squared_error: 0.0013 - val_loss: 0.0013 - val_acc: 0.7734 - val_mean_absolute_error: 0.0255 - val_mean_squared_error: 0.0013
Epoch 36/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0012 - acc: 0.7675 - mean_absolute_error: 0.0256 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_acc: 0.7780 - val_mean_absolute_error: 0.0256 - val_mean_squared_error: 0.0013
Epoch 37/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.7868 - mean_absolute_error: 0.0254 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_acc: 0.7734 - val_mean_absolute_error: 0.0257 - val_mean_squared_error: 0.0013
Epoch 38/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.7739 - mean_absolute_error: 0.0254 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_acc: 0.7827 - val_mean_absolute_error: 0.0255 - val_mean_squared_error: 0.0013
Epoch 39/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7821 - mean_absolute_error: 0.0250 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7734 - val_mean_absolute_error: 0.0251 - val_mean_squared_error: 0.0013
Epoch 40/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0012 - acc: 0.7868 - mean_absolute_error: 0.0251 - mean_squared_error: 0.0012 - val_loss: 0.0013 - val_acc: 0.7617 - val_mean_absolute_error: 0.0254 - val_mean_squared_error: 0.0013
Epoch 41/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7821 - mean_absolute_error: 0.0250 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7804 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0014
Epoch 42/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0011 - acc: 0.7991 - mean_absolute_error: 0.0247 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7757 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 43/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0011 - acc: 0.7821 - mean_absolute_error: 0.0248 - mean_squared_error: 0.0011 - val_loss: 0.0014 - val_acc: 0.7850 - val_mean_absolute_error: 0.0259 - val_mean_squared_error: 0.0014
Epoch 44/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0011 - acc: 0.7862 - mean_absolute_error: 0.0248 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7804 - val_mean_absolute_error: 0.0251 - val_mean_squared_error: 0.0013
Epoch 45/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0011 - acc: 0.7938 - mean_absolute_error: 0.0240 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7827 - val_mean_absolute_error: 0.0252 - val_mean_squared_error: 0.0013
Epoch 46/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0011 - acc: 0.7909 - mean_absolute_error: 0.0242 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7897 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 47/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0011 - acc: 0.7792 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0011 - val_loss: 0.0013 - val_acc: 0.7850 - val_mean_absolute_error: 0.0249 - val_mean_squared_error: 0.0013
Epoch 48/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0010 - acc: 0.7897 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7850 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 49/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0010 - acc: 0.7950 - mean_absolute_error: 0.0239 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7780 - val_mean_absolute_error: 0.0249 - val_mean_squared_error: 0.0013
Epoch 50/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0010 - acc: 0.7856 - mean_absolute_error: 0.0236 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7850 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 51/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0010 - acc: 0.8002 - mean_absolute_error: 0.0237 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7734 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 52/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0010 - acc: 0.7880 - mean_absolute_error: 0.0236 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7757 - val_mean_absolute_error: 0.0251 - val_mean_squared_error: 0.0013
Epoch 53/200
1712/1712 [==============================] - 6s 4ms/step - loss: 9.9723e-04 - acc: 0.8078 - mean_absolute_error: 0.0233 - mean_squared_error: 9.9723e-04 - val_loss: 0.0013 - val_acc: 0.7710 - val_mean_absolute_error: 0.0249 - val_mean_squared_error: 0.0013
Epoch 54/200
1712/1712 [==============================] - 6s 4ms/step - loss: 0.0010 - acc: 0.7991 - mean_absolute_error: 0.0238 - mean_squared_error: 0.0010 - val_loss: 0.0013 - val_acc: 0.7827 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 55/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.8465e-04 - acc: 0.7950 - mean_absolute_error: 0.0233 - mean_squared_error: 9.8465e-04 - val_loss: 0.0012 - val_acc: 0.7827 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0012
Epoch 56/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.7743e-04 - acc: 0.8096 - mean_absolute_error: 0.0231 - mean_squared_error: 9.7743e-04 - val_loss: 0.0013 - val_acc: 0.7780 - val_mean_absolute_error: 0.0251 - val_mean_squared_error: 0.0013
Epoch 57/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.7770e-04 - acc: 0.8061 - mean_absolute_error: 0.0232 - mean_squared_error: 9.7770e-04 - val_loss: 0.0013 - val_acc: 0.7850 - val_mean_absolute_error: 0.0249 - val_mean_squared_error: 0.0013
Epoch 58/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.6140e-04 - acc: 0.8067 - mean_absolute_error: 0.0231 - mean_squared_error: 9.6140e-04 - val_loss: 0.0012 - val_acc: 0.7710 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0012
Epoch 59/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.5847e-04 - acc: 0.8078 - mean_absolute_error: 0.0230 - mean_squared_error: 9.5847e-04 - val_loss: 0.0013 - val_acc: 0.7804 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 60/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.5381e-04 - acc: 0.8032 - mean_absolute_error: 0.0229 - mean_squared_error: 9.5381e-04 - val_loss: 0.0012 - val_acc: 0.7687 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0012
Epoch 61/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.4985e-04 - acc: 0.8049 - mean_absolute_error: 0.0229 - mean_squared_error: 9.4985e-04 - val_loss: 0.0013 - val_acc: 0.7757 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 62/200
1712/1712 [==============================] - 8s 5ms/step - loss: 9.4609e-04 - acc: 0.7991 - mean_absolute_error: 0.0229 - mean_squared_error: 9.4609e-04 - val_loss: 0.0012 - val_acc: 0.7827 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0012
Epoch 63/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.2986e-04 - acc: 0.7996 - mean_absolute_error: 0.0227 - mean_squared_error: 9.2986e-04 - val_loss: 0.0012 - val_acc: 0.7874 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0012
Epoch 64/200
1712/1712 [==============================] - 7s 4ms/step - loss: 9.3451e-04 - acc: 0.8055 - mean_absolute_error: 0.0227 - mean_squared_error: 9.3451e-04 - val_loss: 0.0013 - val_acc: 0.7827 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0013
Epoch 65/200
1712/1712 [==============================] - 8s 4ms/step - loss: 9.2442e-04 - acc: 0.8067 - mean_absolute_error: 0.0226 - mean_squared_error: 9.2442e-04 - val_loss: 0.0012 - val_acc: 0.7850 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0012
Epoch 66/200
1712/1712 [==============================] - 8s 5ms/step - loss: 9.3232e-04 - acc: 0.8084 - mean_absolute_error: 0.0227 - mean_squared_error: 9.3232e-04 - val_loss: 0.0012 - val_acc: 0.7850 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0012
Epoch 67/200
1712/1712 [==============================] - 9s 5ms/step - loss: 9.2445e-04 - acc: 0.8178 - mean_absolute_error: 0.0226 - mean_squared_error: 9.2445e-04 - val_loss: 0.0012 - val_acc: 0.7780 - val_mean_absolute_error: 0.0244 - val_mean_squared_error: 0.0012
Epoch 68/200
1712/1712 [==============================] - 8s 5ms/step - loss: 9.1459e-04 - acc: 0.8148 - mean_absolute_error: 0.0225 - mean_squared_error: 9.1459e-04 - val_loss: 0.0012 - val_acc: 0.7710 - val_mean_absolute_error: 0.0247 - val_mean_squared_error: 0.0012
Epoch 69/200
1712/1712 [==============================] - 10s 6ms/step - loss: 9.1680e-04 - acc: 0.8090 - mean_absolute_error: 0.0225 - mean_squared_error: 9.1680e-04 - val_loss: 0.0012 - val_acc: 0.7780 - val_mean_absolute_error: 0.0245 - val_mean_squared_error: 0.0012
Epoch 70/200
1712/1712 [==============================] - 8s 5ms/step - loss: 9.1135e-04 - acc: 0.8037 - mean_absolute_error: 0.0224 - mean_squared_error: 9.1135e-04 - val_loss: 0.0012 - val_acc: 0.7593 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0012
Epoch 71/200
1712/1712 [==============================] - 10s 6ms/step - loss: 9.2148e-04 - acc: 0.8113 - mean_absolute_error: 0.0226 - mean_squared_error: 9.2148e-04 - val_loss: 0.0012 - val_acc: 0.7757 - val_mean_absolute_error: 0.0245 - val_mean_squared_error: 0.0012
Epoch 72/200
1712/1712 [==============================] - 8s 5ms/step - loss: 8.9164e-04 - acc: 0.7991 - mean_absolute_error: 0.0222 - mean_squared_error: 8.9164e-04 - val_loss: 0.0013 - val_acc: 0.7664 - val_mean_absolute_error: 0.0250 - val_mean_squared_error: 0.0013
Epoch 73/200
1712/1712 [==============================] - 8s 5ms/step - loss: 8.8492e-04 - acc: 0.8148 - mean_absolute_error: 0.0222 - mean_squared_error: 8.8492e-04 - val_loss: 0.0012 - val_acc: 0.7710 - val_mean_absolute_error: 0.0241 - val_mean_squared_error: 0.0012
Epoch 74/200
1712/1712 [==============================] - 8s 5ms/step - loss: 8.7790e-04 - acc: 0.7985 - mean_absolute_error: 0.0221 - mean_squared_error: 8.7790e-04 - val_loss: 0.0012 - val_acc: 0.7687 - val_mean_absolute_error: 0.0244 - val_mean_squared_error: 0.0012
Epoch 75/200
1712/1712 [==============================] - 9s 5ms/step - loss: 8.7870e-04 - acc: 0.8119 - mean_absolute_error: 0.0221 - mean_squared_error: 8.7870e-04 - val_loss: 0.0012 - val_acc: 0.7710 - val_mean_absolute_error: 0.0243 - val_mean_squared_error: 0.0012
Epoch 76/200
1712/1712 [==============================] - 9s 5ms/step - loss: 8.7837e-04 - acc: 0.8096 - mean_absolute_error: 0.0221 - mean_squared_error: 8.7837e-04 - val_loss: 0.0012 - val_acc: 0.7640 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0012
Epoch 77/200
1712/1712 [==============================] - 7s 4ms/step - loss: 8.6791e-04 - acc: 0.8078 - mean_absolute_error: 0.0220 - mean_squared_error: 8.6791e-04 - val_loss: 0.0012 - val_acc: 0.7734 - val_mean_absolute_error: 0.0245 - val_mean_squared_error: 0.0012
Epoch 78/200
1712/1712 [==============================] - 10s 6ms/step - loss: 8.7489e-04 - acc: 0.8189 - mean_absolute_error: 0.0221 - mean_squared_error: 8.7489e-04 - val_loss: 0.0012 - val_acc: 0.7710 - val_mean_absolute_error: 0.0248 - val_mean_squared_error: 0.0012
Epoch 79/200
1712/1712 [==============================] - 10s 6ms/step - loss: 8.7265e-04 - acc: 0.8160 - mean_absolute_error: 0.0220 - mean_squared_error: 8.7265e-04 - val_loss: 0.0012 - val_acc: 0.7804 - val_mean_absolute_error: 0.0245 - val_mean_squared_error: 0.0012
Epoch 80/200
1712/1712 [==============================] - 9s 5ms/step - loss: 8.7470e-04 - acc: 0.8014 - mean_absolute_error: 0.0221 - mean_squared_error: 8.7470e-04 - val_loss: 0.0012 - val_acc: 0.7687 - val_mean_absolute_error: 0.0244 - val_mean_squared_error: 0.0012
Epoch 81/200
1712/1712 [==============================] - 8s 4ms/step - loss: 8.5967e-04 - acc: 0.8096 - mean_absolute_error: 0.0219 - mean_squared_error: 8.5967e-04 - val_loss: 0.0012 - val_acc: 0.7897 - val_mean_absolute_error: 0.0245 - val_mean_squared_error: 0.0012
Epoch 82/200
1712/1712 [==============================] - 7s 4ms/step - loss: 8.5208e-04 - acc: 0.8183 - mean_absolute_error: 0.0218 - mean_squared_error: 8.5208e-04 - val_loss: 0.0012 - val_acc: 0.7827 - val_mean_absolute_error: 0.0243 - val_mean_squared_error: 0.0012
Epoch 83/200
1712/1712 [==============================] - 7s 4ms/step - loss: 8.6500e-04 - acc: 0.8137 - mean_absolute_error: 0.0220 - mean_squared_error: 8.6500e-04 - val_loss: 0.0012 - val_acc: 0.7897 - val_mean_absolute_error: 0.0246 - val_mean_squared_error: 0.0012
Epoch 84/200
1712/1712 [==============================] - 7s 4ms/step - loss: 8.5092e-04 - acc: 0.8067 - mean_absolute_error: 0.0218 - mean_squared_error: 8.5092e-04 - val_loss: 0.0012 - val_acc: 0.7780 - val_mean_absolute_error: 0.0241 - val_mean_squared_error: 0.0012
Epoch 85/200
1712/1712 [==============================] - 7s 4ms/step - loss: 8.4474e-04 - acc: 0.8125 - mean_absolute_error: 0.0218 - mean_squared_error: 8.4474e-04 - val_loss: 0.0012 - val_acc: 0.7757 - val_mean_absolute_error: 0.0243 - val_mean_squared_error: 0.0012
Epoch 00085: early stopping

(4 Convolutions, 2 FCNs, Mean Squared Error) - Adam - BatchNorm - Dropout

In [57]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout, BatchNormalization
from keras.layers import Flatten, Dense

## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model_file = "my_model.h5-4cn-2fc-batchnorm-drop-mse-adam.hd5"

model = Sequential()

# Input Layer: 96 x 96 input neurons
# Convolution Layer 1: 96x96 [filter/same: 3x3] -> 96 x 96 x 10-> maxpooling 2:1 -> BatchNorm
model.add(Convolution2D(filters=6, kernel_size=3, strides=(1,1), padding='same', input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
# Convolution Layer 2: 48 x 48 [filter/same: 3x3] -> 48 x 48 x 20 -> maxpooling 2:1 -> BatchNorm
model.add(Convolution2D(filters=12, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
# Convolution Layer 3: 24 x 24 [filter/same: 3x3] -> 24 x 24 x 30 -> maxpoolling 2:1 -> BatchNorm
model.add(Convolution2D(filters=24, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
# Convolution Layer 4: 12 x 12 [filter/same: 3x3] -> 12 x 12 x 60 -> maxpooling 2:1 -> BatchNorm -> Dropout
model.add(Convolution2D(filters=48, kernel_size=3, strides=(1,1), padding='same'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding='same'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
model.add(Dropout(0.5))
# Flatten
model.add(Flatten())
# # FCN: 12 x 12 x 60 -> 100 -> BatchNorm
model.add(Dense(100, activation='relu'))
model.add(BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001))
# FCN: 144 -> 30
model.add(Dense(30))

# Summarize the model
model.summary()

model.compile(loss='mean_squared_error',
              optimizer='adam',
              metrics=['acc', 'mae', 'mse'] )

train_model(model, model_file, reload=False, train=True, dry=False, epochs=200, batch_size=32, patience=25)
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_82 (Conv2D)           (None, 96, 96, 6)         60        
_________________________________________________________________
max_pooling2d_82 (MaxPooling (None, 48, 48, 6)         0         
_________________________________________________________________
batch_normalization_20 (Batc (None, 48, 48, 6)         24        
_________________________________________________________________
conv2d_83 (Conv2D)           (None, 48, 48, 12)        660       
_________________________________________________________________
max_pooling2d_83 (MaxPooling (None, 24, 24, 12)        0         
_________________________________________________________________
batch_normalization_21 (Batc (None, 24, 24, 12)        48        
_________________________________________________________________
conv2d_84 (Conv2D)           (None, 24, 24, 24)        2616      
_________________________________________________________________
max_pooling2d_84 (MaxPooling (None, 12, 12, 24)        0         
_________________________________________________________________
batch_normalization_22 (Batc (None, 12, 12, 24)        96        
_________________________________________________________________
conv2d_85 (Conv2D)           (None, 12, 12, 48)        10416     
_________________________________________________________________
max_pooling2d_85 (MaxPooling (None, 6, 6, 48)          0         
_________________________________________________________________
batch_normalization_23 (Batc (None, 6, 6, 48)          192       
_________________________________________________________________
dropout_13 (Dropout)         (None, 6, 6, 48)          0         
_________________________________________________________________
flatten_21 (Flatten)         (None, 1728)              0         
_________________________________________________________________
dense_37 (Dense)             (None, 100)               172900    
_________________________________________________________________
batch_normalization_24 (Batc (None, 100)               400       
_________________________________________________________________
dense_38 (Dense)             (None, 30)                3030      
=================================================================
Total params: 190,442
Trainable params: 190,062
Non-trainable params: 380
_________________________________________________________________
Starting training from scratch...
Training the model...
(2140, 96, 96, 1) (2140, 30) 0.0 1.0 -0.9202866 0.9960205
False
False
/Users/safdar/anaconda3/lib/python3.5/site-packages/keras/models.py:944: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
  warnings.warn('The `nb_epoch` argument in `fit` '
Train on 1712 samples, validate on 428 samples
Epoch 1/200
1712/1712 [==============================] - 19s 11ms/step - loss: 0.5499 - acc: 0.0345 - mean_absolute_error: 0.5505 - mean_squared_error: 0.5499 - val_loss: 0.2222 - val_acc: 0.0654 - val_mean_absolute_error: 0.3673 - val_mean_squared_error: 0.2222
Epoch 2/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.1008 - acc: 0.1250 - mean_absolute_error: 0.2492 - mean_squared_error: 0.1008 - val_loss: 0.0442 - val_acc: 0.3364 - val_mean_absolute_error: 0.1643 - val_mean_squared_error: 0.0442
Epoch 3/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0389 - acc: 0.2728 - mean_absolute_error: 0.1528 - mean_squared_error: 0.0389 - val_loss: 0.0151 - val_acc: 0.4860 - val_mean_absolute_error: 0.0940 - val_mean_squared_error: 0.0151
Epoch 4/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0242 - acc: 0.3797 - mean_absolute_error: 0.1199 - mean_squared_error: 0.0242 - val_loss: 0.0089 - val_acc: 0.5841 - val_mean_absolute_error: 0.0725 - val_mean_squared_error: 0.0089
Epoch 5/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0192 - acc: 0.4182 - mean_absolute_error: 0.1066 - mean_squared_error: 0.0192 - val_loss: 0.0060 - val_acc: 0.6121 - val_mean_absolute_error: 0.0593 - val_mean_squared_error: 0.0060
Epoch 6/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0164 - acc: 0.4521 - mean_absolute_error: 0.0984 - mean_squared_error: 0.0164 - val_loss: 0.0054 - val_acc: 0.6542 - val_mean_absolute_error: 0.0559 - val_mean_squared_error: 0.0054
Epoch 7/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0143 - acc: 0.4720 - mean_absolute_error: 0.0917 - mean_squared_error: 0.0143 - val_loss: 0.0047 - val_acc: 0.6589 - val_mean_absolute_error: 0.0513 - val_mean_squared_error: 0.0047
Epoch 8/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0127 - acc: 0.4942 - mean_absolute_error: 0.0867 - mean_squared_error: 0.0127 - val_loss: 0.0045 - val_acc: 0.6659 - val_mean_absolute_error: 0.0506 - val_mean_squared_error: 0.0045
Epoch 9/200
1712/1712 [==============================] - 13s 7ms/step - loss: 0.0115 - acc: 0.5239 - mean_absolute_error: 0.0823 - mean_squared_error: 0.0115 - val_loss: 0.0042 - val_acc: 0.6846 - val_mean_absolute_error: 0.0483 - val_mean_squared_error: 0.0042
Epoch 10/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0108 - acc: 0.5286 - mean_absolute_error: 0.0797 - mean_squared_error: 0.0108 - val_loss: 0.0045 - val_acc: 0.6729 - val_mean_absolute_error: 0.0495 - val_mean_squared_error: 0.0045
Epoch 11/200
1712/1712 [==============================] - 13s 7ms/step - loss: 0.0096 - acc: 0.5146 - mean_absolute_error: 0.0752 - mean_squared_error: 0.0096 - val_loss: 0.0039 - val_acc: 0.6893 - val_mean_absolute_error: 0.0464 - val_mean_squared_error: 0.0039
Epoch 12/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0090 - acc: 0.5432 - mean_absolute_error: 0.0726 - mean_squared_error: 0.0090 - val_loss: 0.0039 - val_acc: 0.6869 - val_mean_absolute_error: 0.0462 - val_mean_squared_error: 0.0039
Epoch 13/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0087 - acc: 0.5555 - mean_absolute_error: 0.0716 - mean_squared_error: 0.0087 - val_loss: 0.0038 - val_acc: 0.7056 - val_mean_absolute_error: 0.0454 - val_mean_squared_error: 0.0038
Epoch 14/200
1712/1712 [==============================] - 11s 7ms/step - loss: 0.0082 - acc: 0.5602 - mean_absolute_error: 0.0694 - mean_squared_error: 0.0082 - val_loss: 0.0038 - val_acc: 0.6565 - val_mean_absolute_error: 0.0456 - val_mean_squared_error: 0.0038
Epoch 15/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0078 - acc: 0.5537 - mean_absolute_error: 0.0672 - mean_squared_error: 0.0078 - val_loss: 0.0037 - val_acc: 0.6822 - val_mean_absolute_error: 0.0445 - val_mean_squared_error: 0.0037
Epoch 16/200
1712/1712 [==============================] - 13s 7ms/step - loss: 0.0073 - acc: 0.5824 - mean_absolute_error: 0.0654 - mean_squared_error: 0.0073 - val_loss: 0.0038 - val_acc: 0.6729 - val_mean_absolute_error: 0.0457 - val_mean_squared_error: 0.0038
Epoch 17/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0071 - acc: 0.5888 - mean_absolute_error: 0.0643 - mean_squared_error: 0.0071 - val_loss: 0.0036 - val_acc: 0.6799 - val_mean_absolute_error: 0.0438 - val_mean_squared_error: 0.0036
Epoch 18/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0067 - acc: 0.6046 - mean_absolute_error: 0.0626 - mean_squared_error: 0.0067 - val_loss: 0.0035 - val_acc: 0.6659 - val_mean_absolute_error: 0.0435 - val_mean_squared_error: 0.0035
Epoch 19/200
1712/1712 [==============================] - 11s 7ms/step - loss: 0.0066 - acc: 0.5917 - mean_absolute_error: 0.0620 - mean_squared_error: 0.0066 - val_loss: 0.0035 - val_acc: 0.7033 - val_mean_absolute_error: 0.0434 - val_mean_squared_error: 0.0035
Epoch 20/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0062 - acc: 0.6250 - mean_absolute_error: 0.0601 - mean_squared_error: 0.0062 - val_loss: 0.0035 - val_acc: 0.6986 - val_mean_absolute_error: 0.0434 - val_mean_squared_error: 0.0035
Epoch 21/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0060 - acc: 0.6285 - mean_absolute_error: 0.0590 - mean_squared_error: 0.0060 - val_loss: 0.0034 - val_acc: 0.7150 - val_mean_absolute_error: 0.0427 - val_mean_squared_error: 0.0034
Epoch 22/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0059 - acc: 0.6209 - mean_absolute_error: 0.0581 - mean_squared_error: 0.0059 - val_loss: 0.0037 - val_acc: 0.7056 - val_mean_absolute_error: 0.0447 - val_mean_squared_error: 0.0037
Epoch 23/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0057 - acc: 0.6466 - mean_absolute_error: 0.0572 - mean_squared_error: 0.0057 - val_loss: 0.0035 - val_acc: 0.7103 - val_mean_absolute_error: 0.0430 - val_mean_squared_error: 0.0035
Epoch 24/200
1712/1712 [==============================] - 13s 7ms/step - loss: 0.0056 - acc: 0.6244 - mean_absolute_error: 0.0568 - mean_squared_error: 0.0056 - val_loss: 0.0032 - val_acc: 0.7009 - val_mean_absolute_error: 0.0417 - val_mean_squared_error: 0.0032
Epoch 25/200
1712/1712 [==============================] - 12s 7ms/step - loss: 0.0054 - acc: 0.6554 - mean_absolute_error: 0.0555 - mean_squared_error: 0.0054 - val_loss: 0.0031 - val_acc: 0.7056 - val_mean_absolute_error: 0.0409 - val_mean_squared_error: 0.0031
Epoch 26/200
1712/1712 [==============================] - 13s 8ms/step - loss: 0.0052 - acc: 0.6437 - mean_absolute_error: 0.0548 - mean_squared_error: 0.0052 - val_loss: 0.0032 - val_acc: 0.7103 - val_mean_absolute_error: 0.0417 - val_mean_squared_error: 0.0032
Epoch 27/200
1712/1712 [==============================] - 13s 8ms/step - loss: 0.0052 - acc: 0.6571 - mean_absolute_error: 0.0544 - mean_squared_error: 0.0052 - val_loss: 0.0033 - val_acc: 0.7126 - val_mean_absolute_error: 0.0423 - val_mean_squared_error: 0.0033
Epoch 28/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0050 - acc: 0.6519 - mean_absolute_error: 0.0537 - mean_squared_error: 0.0050 - val_loss: 0.0031 - val_acc: 0.6916 - val_mean_absolute_error: 0.0405 - val_mean_squared_error: 0.0031
Epoch 29/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0048 - acc: 0.6571 - mean_absolute_error: 0.0526 - mean_squared_error: 0.0048 - val_loss: 0.0031 - val_acc: 0.7173 - val_mean_absolute_error: 0.0405 - val_mean_squared_error: 0.0031
Epoch 30/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0048 - acc: 0.6682 - mean_absolute_error: 0.0522 - mean_squared_error: 0.0048 - val_loss: 0.0030 - val_acc: 0.7103 - val_mean_absolute_error: 0.0403 - val_mean_squared_error: 0.0030
Epoch 31/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0045 - acc: 0.6408 - mean_absolute_error: 0.0509 - mean_squared_error: 0.0045 - val_loss: 0.0030 - val_acc: 0.6752 - val_mean_absolute_error: 0.0397 - val_mean_squared_error: 0.0030
Epoch 32/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0045 - acc: 0.6624 - mean_absolute_error: 0.0509 - mean_squared_error: 0.0045 - val_loss: 0.0030 - val_acc: 0.6752 - val_mean_absolute_error: 0.0402 - val_mean_squared_error: 0.0030
Epoch 33/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0043 - acc: 0.6659 - mean_absolute_error: 0.0493 - mean_squared_error: 0.0043 - val_loss: 0.0030 - val_acc: 0.6939 - val_mean_absolute_error: 0.0401 - val_mean_squared_error: 0.0030
Epoch 34/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0042 - acc: 0.6793 - mean_absolute_error: 0.0491 - mean_squared_error: 0.0042 - val_loss: 0.0031 - val_acc: 0.6869 - val_mean_absolute_error: 0.0412 - val_mean_squared_error: 0.0031
Epoch 35/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0042 - acc: 0.6653 - mean_absolute_error: 0.0485 - mean_squared_error: 0.0042 - val_loss: 0.0028 - val_acc: 0.7150 - val_mean_absolute_error: 0.0387 - val_mean_squared_error: 0.0028
Epoch 36/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0040 - acc: 0.6618 - mean_absolute_error: 0.0477 - mean_squared_error: 0.0040 - val_loss: 0.0027 - val_acc: 0.6963 - val_mean_absolute_error: 0.0379 - val_mean_squared_error: 0.0027
Epoch 37/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0039 - acc: 0.6933 - mean_absolute_error: 0.0473 - mean_squared_error: 0.0039 - val_loss: 0.0027 - val_acc: 0.6846 - val_mean_absolute_error: 0.0374 - val_mean_squared_error: 0.0027
Epoch 38/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0039 - acc: 0.6805 - mean_absolute_error: 0.0466 - mean_squared_error: 0.0039 - val_loss: 0.0027 - val_acc: 0.6963 - val_mean_absolute_error: 0.0377 - val_mean_squared_error: 0.0027
Epoch 39/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0039 - acc: 0.6922 - mean_absolute_error: 0.0468 - mean_squared_error: 0.0039 - val_loss: 0.0028 - val_acc: 0.7009 - val_mean_absolute_error: 0.0392 - val_mean_squared_error: 0.0028
Epoch 40/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0039 - acc: 0.6863 - mean_absolute_error: 0.0469 - mean_squared_error: 0.0039 - val_loss: 0.0027 - val_acc: 0.7079 - val_mean_absolute_error: 0.0379 - val_mean_squared_error: 0.0027
Epoch 41/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0036 - acc: 0.6817 - mean_absolute_error: 0.0455 - mean_squared_error: 0.0036 - val_loss: 0.0026 - val_acc: 0.7196 - val_mean_absolute_error: 0.0368 - val_mean_squared_error: 0.0026
Epoch 42/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0036 - acc: 0.6887 - mean_absolute_error: 0.0452 - mean_squared_error: 0.0036 - val_loss: 0.0025 - val_acc: 0.7056 - val_mean_absolute_error: 0.0362 - val_mean_squared_error: 0.0025
Epoch 43/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0035 - acc: 0.6787 - mean_absolute_error: 0.0445 - mean_squared_error: 0.0035 - val_loss: 0.0025 - val_acc: 0.6963 - val_mean_absolute_error: 0.0361 - val_mean_squared_error: 0.0025
Epoch 44/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0035 - acc: 0.6922 - mean_absolute_error: 0.0443 - mean_squared_error: 0.0035 - val_loss: 0.0025 - val_acc: 0.6706 - val_mean_absolute_error: 0.0364 - val_mean_squared_error: 0.0025
Epoch 45/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0035 - acc: 0.6922 - mean_absolute_error: 0.0448 - mean_squared_error: 0.0035 - val_loss: 0.0024 - val_acc: 0.7056 - val_mean_absolute_error: 0.0360 - val_mean_squared_error: 0.0024
Epoch 46/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0034 - acc: 0.7091 - mean_absolute_error: 0.0439 - mean_squared_error: 0.0034 - val_loss: 0.0025 - val_acc: 0.7079 - val_mean_absolute_error: 0.0359 - val_mean_squared_error: 0.0025
Epoch 47/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0033 - acc: 0.7161 - mean_absolute_error: 0.0431 - mean_squared_error: 0.0033 - val_loss: 0.0024 - val_acc: 0.6939 - val_mean_absolute_error: 0.0357 - val_mean_squared_error: 0.0024
Epoch 48/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0032 - acc: 0.7044 - mean_absolute_error: 0.0426 - mean_squared_error: 0.0032 - val_loss: 0.0025 - val_acc: 0.7103 - val_mean_absolute_error: 0.0362 - val_mean_squared_error: 0.0025
Epoch 49/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0032 - acc: 0.7068 - mean_absolute_error: 0.0423 - mean_squared_error: 0.0032 - val_loss: 0.0024 - val_acc: 0.7126 - val_mean_absolute_error: 0.0355 - val_mean_squared_error: 0.0024
Epoch 50/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0031 - acc: 0.7033 - mean_absolute_error: 0.0420 - mean_squared_error: 0.0031 - val_loss: 0.0025 - val_acc: 0.6916 - val_mean_absolute_error: 0.0361 - val_mean_squared_error: 0.0025
Epoch 51/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0031 - acc: 0.7079 - mean_absolute_error: 0.0419 - mean_squared_error: 0.0031 - val_loss: 0.0023 - val_acc: 0.7173 - val_mean_absolute_error: 0.0345 - val_mean_squared_error: 0.0023
Epoch 52/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0030 - acc: 0.7021 - mean_absolute_error: 0.0409 - mean_squared_error: 0.0030 - val_loss: 0.0024 - val_acc: 0.7103 - val_mean_absolute_error: 0.0355 - val_mean_squared_error: 0.0024
Epoch 53/200
1712/1712 [==============================] - 8s 5ms/step - loss: 0.0030 - acc: 0.7278 - mean_absolute_error: 0.0411 - mean_squared_error: 0.0030 - val_loss: 0.0023 - val_acc: 0.7243 - val_mean_absolute_error: 0.0346 - val_mean_squared_error: 0.0023
Epoch 54/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0030 - acc: 0.7155 - mean_absolute_error: 0.0410 - mean_squared_error: 0.0030 - val_loss: 0.0028 - val_acc: 0.6822 - val_mean_absolute_error: 0.0394 - val_mean_squared_error: 0.0028
Epoch 55/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0032 - acc: 0.6805 - mean_absolute_error: 0.0421 - mean_squared_error: 0.0032 - val_loss: 0.0025 - val_acc: 0.7220 - val_mean_absolute_error: 0.0363 - val_mean_squared_error: 0.0025
Epoch 56/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0029 - acc: 0.7225 - mean_absolute_error: 0.0399 - mean_squared_error: 0.0029 - val_loss: 0.0023 - val_acc: 0.7290 - val_mean_absolute_error: 0.0346 - val_mean_squared_error: 0.0023
Epoch 57/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0029 - acc: 0.7155 - mean_absolute_error: 0.0404 - mean_squared_error: 0.0029 - val_loss: 0.0023 - val_acc: 0.7360 - val_mean_absolute_error: 0.0349 - val_mean_squared_error: 0.0023
Epoch 58/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0028 - acc: 0.7196 - mean_absolute_error: 0.0393 - mean_squared_error: 0.0028 - val_loss: 0.0023 - val_acc: 0.7266 - val_mean_absolute_error: 0.0341 - val_mean_squared_error: 0.0023
Epoch 59/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0028 - acc: 0.7120 - mean_absolute_error: 0.0399 - mean_squared_error: 0.0028 - val_loss: 0.0021 - val_acc: 0.7243 - val_mean_absolute_error: 0.0326 - val_mean_squared_error: 0.0021
Epoch 60/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0028 - acc: 0.7190 - mean_absolute_error: 0.0394 - mean_squared_error: 0.0028 - val_loss: 0.0024 - val_acc: 0.7336 - val_mean_absolute_error: 0.0358 - val_mean_squared_error: 0.0024
Epoch 61/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0027 - acc: 0.7249 - mean_absolute_error: 0.0391 - mean_squared_error: 0.0027 - val_loss: 0.0020 - val_acc: 0.7336 - val_mean_absolute_error: 0.0325 - val_mean_squared_error: 0.0020
Epoch 62/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0026 - acc: 0.7138 - mean_absolute_error: 0.0383 - mean_squared_error: 0.0026 - val_loss: 0.0021 - val_acc: 0.7196 - val_mean_absolute_error: 0.0334 - val_mean_squared_error: 0.0021
Epoch 63/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0026 - acc: 0.7307 - mean_absolute_error: 0.0384 - mean_squared_error: 0.0026 - val_loss: 0.0023 - val_acc: 0.7453 - val_mean_absolute_error: 0.0353 - val_mean_squared_error: 0.0023
Epoch 64/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0027 - acc: 0.7214 - mean_absolute_error: 0.0391 - mean_squared_error: 0.0027 - val_loss: 0.0023 - val_acc: 0.7290 - val_mean_absolute_error: 0.0355 - val_mean_squared_error: 0.0023
Epoch 65/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0027 - acc: 0.7231 - mean_absolute_error: 0.0387 - mean_squared_error: 0.0027 - val_loss: 0.0021 - val_acc: 0.7360 - val_mean_absolute_error: 0.0328 - val_mean_squared_error: 0.0021
Epoch 66/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0026 - acc: 0.7313 - mean_absolute_error: 0.0379 - mean_squared_error: 0.0026 - val_loss: 0.0021 - val_acc: 0.7547 - val_mean_absolute_error: 0.0334 - val_mean_squared_error: 0.0021
Epoch 67/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0025 - acc: 0.7231 - mean_absolute_error: 0.0374 - mean_squared_error: 0.0025 - val_loss: 0.0021 - val_acc: 0.7547 - val_mean_absolute_error: 0.0328 - val_mean_squared_error: 0.0021
Epoch 68/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0024 - acc: 0.7395 - mean_absolute_error: 0.0368 - mean_squared_error: 0.0024 - val_loss: 0.0020 - val_acc: 0.7500 - val_mean_absolute_error: 0.0324 - val_mean_squared_error: 0.0020
Epoch 69/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0024 - acc: 0.7360 - mean_absolute_error: 0.0369 - mean_squared_error: 0.0024 - val_loss: 0.0021 - val_acc: 0.7220 - val_mean_absolute_error: 0.0329 - val_mean_squared_error: 0.0021
Epoch 70/200
1712/1712 [==============================] - 8s 4ms/step - loss: 0.0024 - acc: 0.7296 - mean_absolute_error: 0.0364 - mean_squared_error: 0.0024 - val_loss: 0.0020 - val_acc: 0.7383 - val_mean_absolute_error: 0.0325 - val_mean_squared_error: 0.0020
Epoch 71/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0025 - acc: 0.7325 - mean_absolute_error: 0.0370 - mean_squared_error: 0.0025 - val_loss: 0.0020 - val_acc: 0.7570 - val_mean_absolute_error: 0.0319 - val_mean_squared_error: 0.0020
Epoch 72/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0025 - acc: 0.7348 - mean_absolute_error: 0.0371 - mean_squared_error: 0.0025 - val_loss: 0.0019 - val_acc: 0.7360 - val_mean_absolute_error: 0.0308 - val_mean_squared_error: 0.0019
Epoch 73/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0025 - acc: 0.7220 - mean_absolute_error: 0.0370 - mean_squared_error: 0.0025 - val_loss: 0.0020 - val_acc: 0.7336 - val_mean_absolute_error: 0.0325 - val_mean_squared_error: 0.0020
Epoch 74/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0024 - acc: 0.7389 - mean_absolute_error: 0.0368 - mean_squared_error: 0.0024 - val_loss: 0.0020 - val_acc: 0.7430 - val_mean_absolute_error: 0.0321 - val_mean_squared_error: 0.0020
Epoch 75/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0023 - acc: 0.7354 - mean_absolute_error: 0.0362 - mean_squared_error: 0.0023 - val_loss: 0.0020 - val_acc: 0.7523 - val_mean_absolute_error: 0.0326 - val_mean_squared_error: 0.0020
Epoch 76/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0023 - acc: 0.7377 - mean_absolute_error: 0.0355 - mean_squared_error: 0.0023 - val_loss: 0.0019 - val_acc: 0.7313 - val_mean_absolute_error: 0.0318 - val_mean_squared_error: 0.0019
Epoch 77/200
1712/1712 [==============================] - 11s 6ms/step - loss: 0.0023 - acc: 0.7331 - mean_absolute_error: 0.0357 - mean_squared_error: 0.0023 - val_loss: 0.0018 - val_acc: 0.7500 - val_mean_absolute_error: 0.0308 - val_mean_squared_error: 0.0018
Epoch 78/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0024 - acc: 0.7482 - mean_absolute_error: 0.0365 - mean_squared_error: 0.0024 - val_loss: 0.0021 - val_acc: 0.7523 - val_mean_absolute_error: 0.0330 - val_mean_squared_error: 0.0021
Epoch 79/200
1712/1712 [==============================] - 7s 4ms/step - loss: 0.0023 - acc: 0.7494 - mean_absolute_error: 0.0359 - mean_squared_error: 0.0023 - val_loss: 0.0019 - val_acc: 0.7430 - val_mean_absolute_error: 0.0316 - val_mean_squared_error: 0.0019
Epoch 80/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0022 - acc: 0.7307 - mean_absolute_error: 0.0352 - mean_squared_error: 0.0022 - val_loss: 0.0026 - val_acc: 0.7453 - val_mean_absolute_error: 0.0372 - val_mean_squared_error: 0.0026
Epoch 81/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0022 - acc: 0.7360 - mean_absolute_error: 0.0354 - mean_squared_error: 0.0022 - val_loss: 0.0024 - val_acc: 0.7079 - val_mean_absolute_error: 0.0348 - val_mean_squared_error: 0.0024
Epoch 82/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0023 - acc: 0.7389 - mean_absolute_error: 0.0356 - mean_squared_error: 0.0023 - val_loss: 0.0018 - val_acc: 0.7593 - val_mean_absolute_error: 0.0311 - val_mean_squared_error: 0.0018
Epoch 83/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0021 - acc: 0.7430 - mean_absolute_error: 0.0346 - mean_squared_error: 0.0021 - val_loss: 0.0019 - val_acc: 0.7570 - val_mean_absolute_error: 0.0313 - val_mean_squared_error: 0.0019
Epoch 84/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0022 - acc: 0.7348 - mean_absolute_error: 0.0347 - mean_squared_error: 0.0022 - val_loss: 0.0021 - val_acc: 0.7430 - val_mean_absolute_error: 0.0329 - val_mean_squared_error: 0.0021
Epoch 85/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0022 - acc: 0.7313 - mean_absolute_error: 0.0349 - mean_squared_error: 0.0022 - val_loss: 0.0019 - val_acc: 0.7453 - val_mean_absolute_error: 0.0312 - val_mean_squared_error: 0.0019
Epoch 86/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0021 - acc: 0.7447 - mean_absolute_error: 0.0339 - mean_squared_error: 0.0021 - val_loss: 0.0019 - val_acc: 0.7617 - val_mean_absolute_error: 0.0311 - val_mean_squared_error: 0.0019
Epoch 87/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0023 - acc: 0.7541 - mean_absolute_error: 0.0356 - mean_squared_error: 0.0023 - val_loss: 0.0018 - val_acc: 0.7664 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0018
Epoch 88/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0021 - acc: 0.7395 - mean_absolute_error: 0.0341 - mean_squared_error: 0.0021 - val_loss: 0.0020 - val_acc: 0.7734 - val_mean_absolute_error: 0.0325 - val_mean_squared_error: 0.0020
Epoch 89/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0021 - acc: 0.7488 - mean_absolute_error: 0.0341 - mean_squared_error: 0.0021 - val_loss: 0.0018 - val_acc: 0.7593 - val_mean_absolute_error: 0.0303 - val_mean_squared_error: 0.0018
Epoch 90/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0021 - acc: 0.7494 - mean_absolute_error: 0.0341 - mean_squared_error: 0.0021 - val_loss: 0.0020 - val_acc: 0.7570 - val_mean_absolute_error: 0.0330 - val_mean_squared_error: 0.0020
Epoch 91/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0021 - acc: 0.7535 - mean_absolute_error: 0.0342 - mean_squared_error: 0.0021 - val_loss: 0.0018 - val_acc: 0.7313 - val_mean_absolute_error: 0.0303 - val_mean_squared_error: 0.0018
Epoch 92/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7430 - mean_absolute_error: 0.0339 - mean_squared_error: 0.0020 - val_loss: 0.0019 - val_acc: 0.7336 - val_mean_absolute_error: 0.0318 - val_mean_squared_error: 0.0019
Epoch 93/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0022 - acc: 0.7342 - mean_absolute_error: 0.0348 - mean_squared_error: 0.0022 - val_loss: 0.0024 - val_acc: 0.6612 - val_mean_absolute_error: 0.0361 - val_mean_squared_error: 0.0024
Epoch 94/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0022 - acc: 0.7424 - mean_absolute_error: 0.0345 - mean_squared_error: 0.0022 - val_loss: 0.0017 - val_acc: 0.7523 - val_mean_absolute_error: 0.0302 - val_mean_squared_error: 0.0017
Epoch 95/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0022 - acc: 0.7529 - mean_absolute_error: 0.0350 - mean_squared_error: 0.0022 - val_loss: 0.0019 - val_acc: 0.7710 - val_mean_absolute_error: 0.0315 - val_mean_squared_error: 0.0019
Epoch 96/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7477 - mean_absolute_error: 0.0325 - mean_squared_error: 0.0019 - val_loss: 0.0017 - val_acc: 0.7640 - val_mean_absolute_error: 0.0294 - val_mean_squared_error: 0.0017
Epoch 97/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0021 - acc: 0.7652 - mean_absolute_error: 0.0344 - mean_squared_error: 0.0021 - val_loss: 0.0016 - val_acc: 0.7593 - val_mean_absolute_error: 0.0290 - val_mean_squared_error: 0.0016
Epoch 98/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0020 - acc: 0.7471 - mean_absolute_error: 0.0336 - mean_squared_error: 0.0020 - val_loss: 0.0019 - val_acc: 0.7780 - val_mean_absolute_error: 0.0316 - val_mean_squared_error: 0.0019
Epoch 99/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0020 - acc: 0.7553 - mean_absolute_error: 0.0336 - mean_squared_error: 0.0020 - val_loss: 0.0019 - val_acc: 0.7547 - val_mean_absolute_error: 0.0319 - val_mean_squared_error: 0.0019
Epoch 100/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0020 - acc: 0.7629 - mean_absolute_error: 0.0329 - mean_squared_error: 0.0020 - val_loss: 0.0019 - val_acc: 0.7640 - val_mean_absolute_error: 0.0318 - val_mean_squared_error: 0.0019
Epoch 101/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0019 - acc: 0.7313 - mean_absolute_error: 0.0324 - mean_squared_error: 0.0019 - val_loss: 0.0018 - val_acc: 0.7033 - val_mean_absolute_error: 0.0307 - val_mean_squared_error: 0.0018
Epoch 102/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7599 - mean_absolute_error: 0.0335 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7547 - val_mean_absolute_error: 0.0299 - val_mean_squared_error: 0.0017
Epoch 103/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7611 - mean_absolute_error: 0.0322 - mean_squared_error: 0.0018 - val_loss: 0.0018 - val_acc: 0.7547 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0018
Epoch 104/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7687 - mean_absolute_error: 0.0328 - mean_squared_error: 0.0019 - val_loss: 0.0017 - val_acc: 0.7734 - val_mean_absolute_error: 0.0292 - val_mean_squared_error: 0.0017
Epoch 105/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7605 - mean_absolute_error: 0.0327 - mean_squared_error: 0.0019 - val_loss: 0.0020 - val_acc: 0.7617 - val_mean_absolute_error: 0.0331 - val_mean_squared_error: 0.0020
Epoch 106/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7512 - mean_absolute_error: 0.0333 - mean_squared_error: 0.0020 - val_loss: 0.0018 - val_acc: 0.7056 - val_mean_absolute_error: 0.0304 - val_mean_squared_error: 0.0018
Epoch 107/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7780 - mean_absolute_error: 0.0333 - mean_squared_error: 0.0020 - val_loss: 0.0017 - val_acc: 0.7547 - val_mean_absolute_error: 0.0294 - val_mean_squared_error: 0.0017
Epoch 108/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7617 - mean_absolute_error: 0.0325 - mean_squared_error: 0.0019 - val_loss: 0.0015 - val_acc: 0.7430 - val_mean_absolute_error: 0.0274 - val_mean_squared_error: 0.0015
Epoch 109/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7512 - mean_absolute_error: 0.0330 - mean_squared_error: 0.0019 - val_loss: 0.0017 - val_acc: 0.7780 - val_mean_absolute_error: 0.0302 - val_mean_squared_error: 0.0017
Epoch 110/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0020 - acc: 0.7669 - mean_absolute_error: 0.0329 - mean_squared_error: 0.0020 - val_loss: 0.0019 - val_acc: 0.7710 - val_mean_absolute_error: 0.0312 - val_mean_squared_error: 0.0019
Epoch 111/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7664 - mean_absolute_error: 0.0320 - mean_squared_error: 0.0018 - val_loss: 0.0015 - val_acc: 0.7617 - val_mean_absolute_error: 0.0275 - val_mean_squared_error: 0.0015
Epoch 112/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7664 - mean_absolute_error: 0.0322 - mean_squared_error: 0.0019 - val_loss: 0.0019 - val_acc: 0.7477 - val_mean_absolute_error: 0.0313 - val_mean_squared_error: 0.0019
Epoch 113/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0018 - acc: 0.7494 - mean_absolute_error: 0.0320 - mean_squared_error: 0.0018 - val_loss: 0.0017 - val_acc: 0.7640 - val_mean_absolute_error: 0.0296 - val_mean_squared_error: 0.0017
Epoch 114/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7564 - mean_absolute_error: 0.0316 - mean_squared_error: 0.0018 - val_loss: 0.0015 - val_acc: 0.7710 - val_mean_absolute_error: 0.0274 - val_mean_squared_error: 0.0015
Epoch 115/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7728 - mean_absolute_error: 0.0328 - mean_squared_error: 0.0019 - val_loss: 0.0018 - val_acc: 0.7710 - val_mean_absolute_error: 0.0310 - val_mean_squared_error: 0.0018
Epoch 116/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7734 - mean_absolute_error: 0.0312 - mean_squared_error: 0.0017 - val_loss: 0.0018 - val_acc: 0.7640 - val_mean_absolute_error: 0.0308 - val_mean_squared_error: 0.0018
Epoch 117/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7593 - mean_absolute_error: 0.0317 - mean_squared_error: 0.0018 - val_loss: 0.0020 - val_acc: 0.7757 - val_mean_absolute_error: 0.0331 - val_mean_squared_error: 0.0020
Epoch 118/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7623 - mean_absolute_error: 0.0325 - mean_squared_error: 0.0019 - val_loss: 0.0018 - val_acc: 0.7173 - val_mean_absolute_error: 0.0310 - val_mean_squared_error: 0.0018
Epoch 119/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0019 - acc: 0.7523 - mean_absolute_error: 0.0330 - mean_squared_error: 0.0019 - val_loss: 0.0016 - val_acc: 0.7687 - val_mean_absolute_error: 0.0291 - val_mean_squared_error: 0.0016
Epoch 120/200
1712/1712 [==============================] - 10s 6ms/step - loss: 0.0019 - acc: 0.7693 - mean_absolute_error: 0.0330 - mean_squared_error: 0.0019 - val_loss: 0.0021 - val_acc: 0.7921 - val_mean_absolute_error: 0.0330 - val_mean_squared_error: 0.0021
Epoch 121/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7599 - mean_absolute_error: 0.0316 - mean_squared_error: 0.0018 - val_loss: 0.0015 - val_acc: 0.7523 - val_mean_absolute_error: 0.0280 - val_mean_squared_error: 0.0015
Epoch 122/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7541 - mean_absolute_error: 0.0320 - mean_squared_error: 0.0018 - val_loss: 0.0022 - val_acc: 0.7103 - val_mean_absolute_error: 0.0337 - val_mean_squared_error: 0.0022
Epoch 123/200
1712/1712 [==============================] - 9s 6ms/step - loss: 0.0018 - acc: 0.7833 - mean_absolute_error: 0.0315 - mean_squared_error: 0.0018 - val_loss: 0.0018 - val_acc: 0.7570 - val_mean_absolute_error: 0.0305 - val_mean_squared_error: 0.0018
Epoch 124/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7815 - mean_absolute_error: 0.0318 - mean_squared_error: 0.0018 - val_loss: 0.0018 - val_acc: 0.7664 - val_mean_absolute_error: 0.0306 - val_mean_squared_error: 0.0018
Epoch 125/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7722 - mean_absolute_error: 0.0313 - mean_squared_error: 0.0017 - val_loss: 0.0018 - val_acc: 0.7547 - val_mean_absolute_error: 0.0311 - val_mean_squared_error: 0.0018
Epoch 126/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7535 - mean_absolute_error: 0.0321 - mean_squared_error: 0.0019 - val_loss: 0.0016 - val_acc: 0.7687 - val_mean_absolute_error: 0.0290 - val_mean_squared_error: 0.0016
Epoch 127/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7675 - mean_absolute_error: 0.0309 - mean_squared_error: 0.0017 - val_loss: 0.0017 - val_acc: 0.7734 - val_mean_absolute_error: 0.0301 - val_mean_squared_error: 0.0017
Epoch 128/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0019 - acc: 0.7687 - mean_absolute_error: 0.0323 - mean_squared_error: 0.0019 - val_loss: 0.0019 - val_acc: 0.7734 - val_mean_absolute_error: 0.0322 - val_mean_squared_error: 0.0019
Epoch 129/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7710 - mean_absolute_error: 0.0313 - mean_squared_error: 0.0018 - val_loss: 0.0016 - val_acc: 0.7850 - val_mean_absolute_error: 0.0287 - val_mean_squared_error: 0.0016
Epoch 130/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7734 - mean_absolute_error: 0.0311 - mean_squared_error: 0.0017 - val_loss: 0.0019 - val_acc: 0.7640 - val_mean_absolute_error: 0.0318 - val_mean_squared_error: 0.0019
Epoch 131/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0018 - acc: 0.7634 - mean_absolute_error: 0.0316 - mean_squared_error: 0.0018 - val_loss: 0.0015 - val_acc: 0.7804 - val_mean_absolute_error: 0.0280 - val_mean_squared_error: 0.0015
Epoch 132/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7599 - mean_absolute_error: 0.0306 - mean_squared_error: 0.0017 - val_loss: 0.0018 - val_acc: 0.7780 - val_mean_absolute_error: 0.0307 - val_mean_squared_error: 0.0018
Epoch 133/200
1712/1712 [==============================] - 9s 5ms/step - loss: 0.0017 - acc: 0.7640 - mean_absolute_error: 0.0310 - mean_squared_error: 0.0017 - val_loss: 0.0016 - val_acc: 0.7804 - val_mean_absolute_error: 0.0284 - val_mean_squared_error: 0.0016
Epoch 00133: early stopping

Step 7: (ANALYSIS) Answer a few questions and visualize the test predictions

Here are the results of training using 2 optimizers (Adam and RMSProp), and in each case, using no dropout, then using dropout, and then adding additional batch normalization.

Architecture Epochs Train Loss Val Loss Train Acc Val Acc
3CN/1FC/RMSProp/NoDrop 38 0.0006 0.0018 88 78
3CN/1FC/RMSProp/Drop 52 0.0013 0.0015 81 79
3CN/1FC/Adam/Drop 96 0.0009 0.0013 81 81
3CN/1FC/Adam/Drop/Batch 70 0.0063 0.0034 68 72
4CN/2FC/RMSProp/NoDrop 46 0.0004 0.0020 88 75
4CN/2FC/RMSProp/Drop 50 0.0009 0.0013 80 78
4CN/2FC/Adam/NoDrop 45 0.0004 0.0016 86 79
4CN/2FC/Adam/Drop 85 0.0008 0.0012 81 78
4CN/2FC/Adam/Drop/Batch 133 0.0017 0.0016 77 78

Question 1: Outline the steps you took to get to your final neural network architecture and your reasoning at each step.

Answer: My goal is generally to create the smallest network that overfits to the training set. And then find ways to regularize it to improve the validation performance. In all cases below, I had setup early stopping with a patience of 25 epochs and an expected reduction in validation loss of at least 0.0001 units for training to continue.

I found that with 3 convolutional layers and 1 fully-connected layer, the network achieved pretty satisfactory results. Without dropout, the network overfitted to the training set and underfitted to the validation set by a factor of ~10% in accuracy. The losses too were accordingly wide apart. This was also obvious through manual testing. For example, the network would not adjust its keypoints when the subject's mouth was not in a closed position, nor when the eyes and eyebrows would wince. It had learned a set of patterns of points, and was not adapting too well to variations in faces. However, training was pretty fast, even on my Macbook, since there were only ~100K parameters to train.

I then added regularization through a dropout layer, which drastically improved the performance on the validation set, however, at the expense of increasing the bias (as can be seen in the table above). The best validation performance achieved with 3 convolutional layers, 1 fully connected layer, and dropout was a loss of 0.0013 and accuracy of 81%.

Below is an illustration of the difference that regularization made, on the network above:

Without dropout With dropout

It was for curiosity that I attempted increasing the depth of the network by using 4 convolution layers and 2 fully-connected layers to see if it would improve the performance overall. Again, I tested without any regularization (no dropout). Strangely, the network didn't seem to do any better on the training data than using fewer layers, though that might also be because of early stopping kicking in too early. However, I am not convinced this was the case. The network trained for more epochs, which makes sense since there were now ~189K parameters to train, but the overfitted performance was the same as the prior architecture.

I then attempted regularization by adding a dropout layer. This achieved a marked improvement in validation loss, reaching as low as 0.0012 units for validation data. However, validation accuracy remained around 78%, which was in the same ballpark as the performance in the prior architecture. This was the lowest validation loss I had achieved so far, and I decided to use that architecture (and trained model) for the rest of this project. That model is saved in the file named: ''.

Here is the difference that regularization made on the deeper network:

Without dropout With dropout

The reason I used only 1 dropout (and no more) in both network architectures above, is that even with that on dropout, the accuracy that the network achieved for both training and validation sets converged. There didn't seem to be a reason to add more regularization in this case, because the only difference that would have made would have been to increase both the training time and the bias.

Another behavior I saw was with the performance of the both network architectures above, after adding BatchNormalization (in addition to Dropout). Not only did the networks continue training beyond what they did without BN, but they also performed at best the same on both training and validation sets, as compared to the performance of the respective architectures without batch normalization. For these two reasons, I stuck to just 1 dropout layer, and no batch normalization, for the 'winning' network.

Below is an illustration of the difference that batch normalization produced, on the shallower network:

Only dropout Dropout + batch normalization

And below is the difference it made for the deeper network:

Only dropout Dropout + batchnormalization

The only explanation I can come up with, for the two strange behaviors above -- i.e, (a) that a deeper network didn't seem to have higher variance than the shallower one, and (b) that batch normalization required more epochs of training, and still didn't produce better results -- is that the eary stopping feature that I relied on might have aborted training too soon in both cases. Perhaps a patience of 25 is too short, and a reduction of 0.0001 units of validation loss was too high of an expectation at each epoch. Perhaps if the settings were more lenient, the more complex network architecture with batch normalization would have come out as the winner.

In any case, I had achieved a substantially good validation loss (0.0012) and validation accuracy (78%), for the purposes of this project, and decided not to go any further down that rabbit hole. 4 convolution layers + 2 fully-connected layers, with one dropout (of 50% drop probability), was the winning architecture. The only remaining item was the selection of the optimizer, which I have discussed next.

Question 2: Defend your choice of optimizer. Which optimizers did you test, and how did you determine which worked best?

Answer: I tried 2 optimizers - RMSProp and Adam. Adam is considered one of the better performing optimizers, and it lived up to that reputation in my tests.

I based the decision (about which one worked best) on the final validation loss and accuracy that was achieved using each of the 2 optimizers, keeping all else equal. In other words, in all cases, i.e, with both a shallower or deeper network, and both with or without a dropout, Adam achieved better numbers than RMSProp.

Below is the performance of the shallower network with regularization, using RMSProp and Adam:

Using RMSProp Using Adam

And below is the same for the deeper network, again using RMSProp and Adam:

Using RMSProp Using Adam

Question 3: Do you notice any evidence of overfitting or underfitting in the above plot? If so, what steps have you taken to improve your model? Note that slight overfitting or underfitting will not hurt your chances of a successful submission, as long as you have attempted some solutions towards improving your model (such as regularization, dropout, increased/decreased number of layers, etc).

Answer: I have already discussed at length the process that I followed when adding regularization to both network architectures above. There indeed was overfitting observed -- nearly a 8-10% difference in accuracy between training and validation sets, when no regularization was used.

Below are the performances of the two network architectures, without regularization:

Shallow network without dropout Deeper network without dropout

Below are the performances of the same two network architectures, after adding regularization (1 dropout of 50% probability):

Shallow network with dropout Deeper network with dropout

There are potentially other things I could have explored to improve the overall performance of the network:

  • Augmented data: This could be by doing a horizontal flip of each input image (with a probability of 50%). Other options would be to do affine transformations, or perspective transforms.
  • Added more layers (both convolutional and fully-connected)
  • Explore Batch Normalization with a more lenient early stopping criteria

Visualize a Subset of the Test Predictions

Execute the code cell below to visualize your model's predicted keypoints on a subset of the testing images.

In [39]:
y_test = model.predict(X_test)
fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_test[i], y_test[i], ax)

Step 8: Complete the pipeline

With the work you did in Sections 1 and 2 of this notebook, along with your freshly trained facial keypoint detector, you can now complete the full pipeline. That is given a color image containing a person or persons you can now

  • Detect the faces in this image automatically using OpenCV
  • Predict the facial keypoints in each face detected in the image
  • Paint predicted keypoints on each face detected

In this Subsection you will do just this!

(IMPLEMENTATION) Facial Keypoints Detector

Use the OpenCV face detection functionality you built in previous Sections to expand the functionality of your keypoints detector to color images with arbitrary size. Your function should perform the following steps

  1. Accept a color image.
  2. Convert the image to grayscale.
  3. Detect and crop the face contained in the image.
  4. Locate the facial keypoints in the cropped image.
  5. Overlay the facial keypoints in the original (color, uncropped) image.

Note: step 4 can be the trickiest because remember your convolutional network is only trained to detect facial keypoints in $96 \times 96$ grayscale images where each pixel was normalized to lie in the interval $[0,1]$, and remember that each facial keypoint was normalized during training to the interval $[-1,1]$. This means - practically speaking - to paint detected keypoints onto a test face you need to perform this same pre-processing to your candidate face - that is after detecting it you should resize it to $96 \times 96$ and normalize its values before feeding it into your facial keypoint detector. To be shown correctly on the original image the output keypoints from your detector then need to be shifted and re-normalized from the interval $[-1,1]$ to the width and height of your detected face.

When complete you should be able to produce example images like the one below

In [40]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')


# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# plot our image
def show(image):
    fig = plt.figure(figsize = (9,9))
    ax1 = fig.add_subplot(111)
    ax1.set_xticks([])
    ax1.set_yticks([])
    ax1.set_title('image copy')
    ax1.imshow(image)
    
show(image)
In [41]:
from sklearn.preprocessing import normalize

### TODO: Use the face detection code we saw in Section 1 with your trained conv-net 
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
image_with_faces, face_regions = detect(image, face_cascade, None)
print ("Number of faces: ", len(face_regions))

#
# Method to map a function to a list of faces on a given image
#
def process_faces(image, faces, callback):
    image = np.copy(image)
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    if faces is not None:
        for (x,y,w,h) in faces:
            face_color = image[y:y+h, x:x+w, :]
            face_gray = gray[y:y+h, x:x+w]
            processed_color = callback(face_color, face_gray)
            image[y:y+h, x:x+w, :] = processed_color
    return image

def find_keypoints(face_gray):
    # Resize image to 96x96
    resized_gray = cv2.resize(face_gray, (96,96))

    # Normalize to range [0,1]
    face_gray_norm = normalize(resized_gray, axis=0, norm='l1')

    # Query model for keypoints
    global model
    X = np.reshape(face_gray_norm, (1,96,96,1))
#         show(X[0,:,:,0]) # If this gets drawn, it means it was reshaped well
    points = model.predict(X)
    points = points * 48 + 48 # undo the normalization

    # Obtain the X and Y coordinates of each keypoint:
    xs = points[0,0::2]
    ys = points[0,1::2]

    # Adjust keypoints for original sized image:
    keypoints = [(int(face_gray.shape[0]/96 * x), int(face_gray.shape[1]/96 * y)) for (x,y) in zip(xs,ys)]

    return keypoints

def draw_points(face_color, points):
    marked = np.copy(face_color)
    for (x,y) in points:
        marked = cv2.circle(marked, (x,y), 4, (0,255,0),thickness=-1)
    return marked

def mark_facial_keypoints(face_color, face_gray):
    keypoints = find_keypoints(face_gray)
    marked = draw_points(face_color, keypoints)
    return marked

processed_image = process_faces(image, face_regions, mark_facial_keypoints)

## TODO : Paint the predicted keypoints on the test image
show(processed_image)
Number of faces:  2

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add facial keypoint detection to your laptop camera - as illustrated in the gif below.

img

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for keypoint detection and marking in the previous exercise and you should be good to go!

In [28]:
import cv2
import time 
from keras.models import load_model
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # keep video stream open
    face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
    while rval:
        # plot image from camera with detections marked
        _, face_regions = detect(frame, face_cascade, None)
#         print ("Number of faces: ", len(face_regions))
        marked = process_faces(frame, face_regions, mark_facial_keypoints)
        
        cv2.imshow("face detection activated", marked)
        
        # exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # destroy windows
            cv2.destroyAllWindows()
            
            # hack from stack overflow for making sure window closes on osx --> https://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()  
In [29]:
# Run your keypoint face painter
# laptop_camera_go()

(Optional) Further Directions - add a filter using facial keypoints

Using your freshly minted facial keypoint detector pipeline you can now do things like add fun filters to a person's face automatically. In this optional exercise you can play around with adding sunglasses automatically to each individual's face in an image as shown in a demonstration image below.

To produce this effect an image of a pair of sunglasses shown in the Python cell below.

In [42]:
# Load in sunglasses image - note the usage of the special option
# cv2.IMREAD_UNCHANGED, this option is used because the sunglasses 
# image has a 4th channel that allows us to control how transparent each pixel in the image is
sunglasses = cv2.imread("images/sunglasses_4.png", cv2.IMREAD_UNCHANGED)

# Plot the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.imshow(sunglasses)
ax1.axis('off');

This image is placed over each individual's face using the detected eye points to determine the location of the sunglasses, and eyebrow points to determine the size that the sunglasses should be for each person (one could also use the nose point to determine this).

Notice that this image actually has 4 channels, not just 3.

In [30]:
# Print out the shape of the sunglasses image
print ('The sunglasses image has shape: ' + str(np.shape(sunglasses)))
The sunglasses image has shape: (1123, 3064, 4)

It has the usual red, blue, and green channels any color image has, with the 4th channel representing the transparency level of each pixel in the image. Here's how the transparency channel works: the lower the value, the more transparent the pixel will become. The lower bound (completely transparent) is zero here, so any pixels set to 0 will not be seen.

This is how we can place this image of sunglasses on someone's face and still see the area around of their face where the sunglasses lie - because these pixels in the sunglasses image have been made completely transparent.

Lets check out the alpha channel of our sunglasses image in the next Python cell. Note because many of the pixels near the boundary are transparent we'll need to explicitly print out non-zero values if we want to see them.

In [31]:
# Print out the sunglasses transparency (alpha) channel
alpha_channel = sunglasses[:,:,3]
print ('the alpha channel here looks like')
print (alpha_channel)

# Just to double check that there are indeed non-zero values
# Let's find and print out every value greater than zero
values = np.where(alpha_channel != 0)
print ('\n the non-zero values of the alpha channel look like')
print (values)
the alpha channel here looks like
[[0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 ...
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]]

 the non-zero values of the alpha channel look like
(array([  17,   17,   17, ..., 1109, 1109, 1109]), array([ 687,  688,  689, ..., 2376, 2377, 2378]))

This means that when we place this sunglasses image on top of another image, we can use the transparency channel as a filter to tell us which pixels to overlay on a new image (only the non-transparent ones with values greater than zero).

One last thing: it's helpful to understand which keypoint belongs to the eyes, mouth, etc. So, in the image below, we also display the index of each facial keypoint directly on the image so that you can tell which keypoints are for the eyes, eyebrows, etc.

With this information, you're well on your way to completing this filtering task! See if you can place the sunglasses automatically on the individuals in the image loaded in / shown in the next Python cell.

In [43]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# Plot the image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[43]:
<matplotlib.image.AxesImage at 0x1843381f60>
In [44]:
## (Optional) TODO: Use the face detection code we saw in Section 1 with your trained conv-net to put
## sunglasses on the individuals in our test image
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
image_with_faces, face_regions = detect(image, face_cascade, None)
print ("Number of faces: ", len(face_regions))

#KeypointIDs:
LeftEyeLeftCorner = 3
LeftEyeRightCorner = 2
LeftEyeCenter = 0
LeftEyebrowLeftCorner = 7
LeftEyebrowRightCorner = 6
RightEyeRightCorner = 5
RightEyeLeftCorner = 4
RightEyeCener = 1
RightEyebrowLeftCorner = 8
RightEyebrowRightCorner = 9
NoseCenter = 10
def overlay_sunglasses(face_color, keypoints):
    # Sunglass adjustments:
    # - Length: distance between LeftEyeLeftCorner[x]' and 'RightEyeRightCorner[x]'
        # Since we are not dealing with sunglass orientation right now. So we take
        # the length only along the X-axis.
    length = int((keypoints[LeftEyebrowLeftCorner][0] - keypoints[RightEyebrowRightCorner][0]) * 1.35)

    # - Height: distance between LeftEyebrowRightCorner[y] and NoseCenter[y]
        # Same as above reason: No orientation, so height is calculated only along y axis.
    height = keypoints[NoseCenter][1] - keypoints[LeftEyebrowRightCorner][1]

    assert length > height
    
    # - Position: mid-point of lower edge sits right above the NoseCenter
    nose = keypoints[NoseCenter] # expected position of the mid-point of lower edge of 'sunglasses'

    # - Orientation: sunglass's euler angles are out of scope for this project.
    global sunglasses
    resized_sunglasses = cv2.resize(sunglasses, (length,height))
    upper_left = [(nose[0] - int(length/2)), nose[1] - height]
    lower_right = [(nose[0] + int(length/2)), nose[1]]

    #
    # Alpha-blend sunglasses onto face
    # See: https://www.learnopencv.com/alpha-blending-using-opencv-cpp-python/
    #
    # Separate out background, foreground and alpha
    blended = np.copy(face_color).astype(float)
    background = blended[upper_left[1]:upper_left[1]+height, upper_left[0]:upper_left[0]+length, :]
    foreground = np.copy(resized_sunglasses[:,:,:3]).astype(float)
    assert background.shape == foreground.shape, "Shapes did not match: {} not equal to {}".format(background.shape, foreground.shape)
    alpha = resized_sunglasses[:,:,3].astype(float)/255 # Normalize the alpha mask to keep intensity between 0 and 1
    alpha = np.dstack((alpha, alpha, alpha))

    # Multiply the foreground with the alpha matte
    assert alpha.shape[:2] == foreground.shape[:2], "Shapes did not match: {} not equal to {}".format(alpha.shape, foreground.shape)
    foreground = cv2.multiply(alpha, foreground)

    # Multiply the background with ( 1 - alpha )
    background = cv2.multiply(1.0 - alpha, background)

    # Add the masked foreground and background.
    blended[upper_left[1]:upper_left[1]+height, upper_left[0]:upper_left[0]+length, :] = cv2.add(foreground, background)
    
    return blended

#     marked = np.copy(face_color)
    
#     for (x,y) in keypoints:
#         marked = cv2.circle(marked, (x,y), 4, (0,255,0),thickness=-1)
#     return marked

def draw_facial_sunglasses(face_color, face_gray):
    keypoints = find_keypoints(face_gray)
    marked = overlay_sunglasses(face_color, keypoints)
    return marked

processed_image = process_faces(image, face_regions, draw_facial_sunglasses)

## TODO : Paint the predicted keypoints on the test image
show(processed_image)
Number of faces:  2

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add the sunglasses filter to your laptop camera - as illustrated in the gif below.

img

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for adding sunglasses to someone's face in the previous optional exercise and you should be good to go!

In [45]:
import cv2
import time 
from keras.models import load_model
import numpy as np

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')
    while rval:
        # Plot image from camera with detections marked
        image_with_faces, face_regions = detect(frame, face_cascade, None)
        frame = process_faces(frame, face_regions, draw_facial_sunglasses)
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [46]:
# Load facial landmark detector model
model = load_model('my_model.h5-4cn-2fc-drop-mse-adam.hd5')

# Run sunglasses painter
# laptop_camera_go()